This paper mainly introduces the basic knowledge of variables in C #, and has a good reference value. Let's take a look at the little series.
Use variables in 3 steps: Declare, assign, use.
Syntax for declaring variables: data type variable name;
syntax for assigning a variable: variable name = value;
Namespace Test{class Program { static void Main (string[] args) { int age;//declare variable, type int, variable name age = 18 ;//Assign the variable age to Console.WriteLine ("I Am" +age= "year");//print Ages = 19;//Modify the value of the variable age Console.WriteLine ("I "+age+");//Print Age }}}
The result of the operation is:
The Declaration and assignment of a variable can be done at the same time, the first two lines in the main () method of the above code can be rewritten as:
int age=18;//声明并赋值
Exercises:
static void Main (string[] args) {int age;//age =-20; Console.WriteLine ("I am {0} years old this year", age); age = age-2;}
This code prints: I'm 21 years old.