I. Constants
A constant is a variable whose value does not change during use. Keywords in front of the variable during declaration and initialization
Const int a = 100; //
Constant features:
Using constants in a program must include at least
For example:
j= time= j=
Errors generated after compilation:
For
Both constants and read-only constants can only be accessed and cannot be modified. However, their assignment time is not the same. Generally, constants are determined during compilation and assigned constant values. Read-Only is actually a variable that will be assigned a value only when it needs to be dynamically loaded during runtime, and this value cannot be changed once it is assigned.
Ii. type inference
Use of type inference
Int someNumber = 0;
It becomes
Var someNumber = 0;
Even if
The following is another example:
Main( name = age= isRabbit====+++
Compile and run the program:
Name is type System. String
Age is type System. Int32
IsRabbit is type System. Boolean
Use
The scope of a variable is the code area that can access the variable. In general, make sure that the scope has the following rules:
It is common to provide the same variable name for different variables in different parts of a large program. As long as the variable scope is different parts of the program, there will be no problem. And will not produce fuzzy. Note that local variables with the same name cannot be declared twice in the same scope, so the following code cannot be used:
Int x = 20;
Int x = 30;
Let's take a look at the following example:
i=;i<;i++ i=;i>=
This code should be noted. I appears twice, but they are all variables relative to the loop body.
Another example:
j=( i=;i<;i++ j=; Console.WriteLine(j+
Field or local variable scope conflict: in some cases, the same name can be distinguished