Use of variables
A variable is a name that represents the data stored in memory when the program executes, and is used for program Access data.
Variable declaration
Before you can use a variable, you must declare it: give the variable a name and associate a type, and let the compiler allocate a chunk of memory for it. (A long piece of crap)
string name; // A variable is declared, the name is named, and the type is string
You can also put multiple variable declarations in a single statement, but must be of the same type, with a comma interval between them.
Types of variables
Local variables save temporary data at method scope
field holds data related to type or type instance, is a member of type
parameter is used for one method to pass data to another method temporary variable
A member of an ordered set of data of the same type of an array element
Variables that can be initialized automatically
1 class Program2 {3 Static intNumber//class field4 Static voidMain (string[] args)5 {6 Console.WriteLine (number);7 byte[] Arrs =New byte[4];8Console.WriteLine (arrs[1]);//array elements9Anystruct any=Newanystruct ();TenConsole.WriteLine (Any.field);//structure Field One } A } - - structanystruct { the Public Doublefield; -}
C # variables