C# Basic syntax for variable declaration
In C#, the basic syntax for declaring variables is as follows:
<code>数据类型 变量名;</code>
Copy after login
Among them:
- Data type: The type of data stored in the variable, such as int, string, double, etc.
-
Variable name: The name of the variable consists of letters, numbers, and underscores, and must start with a letter.
Example:
<code>int age;
string name;
double salary;</code>
Copy after login
This code declares three variables:
-
age:one Variable to store integers.
-
name: A variable that stores a string.
-
salary: A variable that stores a double-precision floating point number.
Note:
- The variable name cannot be the same as the C# keyword.
- Variable names cannot contain spaces.
- Variables must be declared before use.
- The type of a variable cannot be changed after declaration.
The above is the detailed content of What is the basic syntax of c# variable declaration?. For more information, please follow other related articles on the PHP Chinese website!