Variables relate to the storage of data, the name of a store for program operation, each variable is a specific type, and the type determines the memory size and layout of the variable.
Note: Must be declared first, after assignment, to use.
Three ways of declaring:
1. Declare first, then assign value. such as: int i; I=1;
2. When defining variables, assign values directly. such as: int i=1;
3. Declare more than one type variable at a time, separating multiple variable names with commas and ending with semicolons. such as: int a,b,c;
Declaring variable formats:
<type><name>
Variable naming rules:
The first character of a variable name must be a letter, underscore, or @.
The subsequent characters can be letters, underscores, or numbers.
Note:C # is sensitive to size , so be careful not to forget the correct case when declaring a variable.
Naming conventions:
Pascalcase
CamelCase
Description: Use casing in variable names to indicate their purpose. They are applied to names that consist of multiple words and specify
Each word in the name is lowercase except for the first letter capitalized. In CamelCase, there is one more rule, that is, the first word starts with a lowercase letter.
Microsoft recommends: For simple variables, use the CamelCase rule, while for more advanced naming use Pascalcase.
- Assigning values to variables
Assignment operator: = is an equal sign.
Example:
int i;//Declaration
i=1;//Assignment Value
Finally, here's a simple example:
1 usingSystem;2 namespacehelloworldapplication3 {4 classHelloWorld5 {6 /*the variable of my first C # program*/7 Static voidMain (string[] args)8 {9 //Variable DeclarationTen stringstr; One //assigning values to variables Astr ="Hello World" ; - Console.WriteLine (str); - Console.readkey (); the } - } -}View Code
C # Getting Started note 2 variables