When we need to access the information stored in a variable, we only need to use the name of the variable. When naming variables, you must comply with the regulations of the C# language:
●The variable name must start with a letter
●The variable name can only be composed of letters, numbers, and underscores, and cannot contain spaces, Punctuation marks, operators and other symbols.
●The variable name cannot be the same as the keyword name in C#. These keywords are given in Appendix A.
●The variable name cannot be the same as the library function name in C#.
But there is one exception in C#, that is, the prefix "@" is allowed before the variable name. In this case, we can use the prefix "@" plus the keyword as the name of the variable. This is mainly to avoid conflicts when interacting with other languages. Because the prefix "@" is not actually part of the name, other programming languages ??will treat it as an ordinary variable name. In other cases, we do not recommend using the prefix "@" as part of a variable name.
The following are some examples of legal and illegal variable names:
int
i;
//Legal
p>int
No.1;
//Illegal, containing illegal characters
string
total;
//Legal
char
use;
//Illegal, the same as the keyword name
char
@use;
//Legal
float
Main;
//Illegal, Same as the function name
Although variable names that meet the above requirements can be used, we still hope that when naming the variables, we should give descriptive names so that the program written in this way is convenient understand. For example, the name of a message string can be called s_message; but e90PT is not a good variable name. This article was published on
(Programming Introduction Network)
We can name multiple variables of the same type in one statement, such as:
int
a, b, c=50, d;