This article mainly introduces the basic knowledge of variables in C# and has a good reference value. Let’s take a look with the editor below
Using variables is divided into 3 steps: declaration, assignment, and use.
The syntax for declaring variables: data type variable name;
The syntax for assigning values to variables: variable name=value;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
The running result is:
The declaration and assignment of variables can be completed at the same time, in the Main() method of the above code The first two lines can be rewritten as:
int age=18;//Declaration and assignment
Exercise questions:
1 2 3 4 5 6 7 8 9 |
|
What this code prints is: I am 21 years old this year
The above is the detailed content of Introduction to C# Basics-Introduction to Variables. For more information, please follow other related articles on the PHP Chinese website!