"C # Advanced Programming" study notes, Day3

  I have to say that this book is very comprehensive basic knowledge, today re-learn the variables that knowledge, benefit.

  variable

  Variable declaration:

  A variable datatype identifier; statements made in the form of, for example, int i;

  After variable declarations may receive data, but the data must conform to the declared type, such as int type can not speak string variable assignment e.g. int i = "string"; ×

  Type inference may be variable declaration var keyword, it will determine the data type of the variable in the variable initialization. Thereafter this variable can not change the type, strongly typed must be inferred based on the type.

  You can create user-defined by the object as a type, but you must create an object on the heap by the new keyword in the initialization, this variable will be stored on this object reference

  One thing to note is the use of variables will be recognized compiler errors before initialization. We need to initialize a variable that is the assignment before use.

  Scope of variables:

  Variables are scoped variables are called braces declaration occurs.

  We can not declare a variable with a scope that already exist again, otherwise the compiler will not recognize the variable you are using which one, that is wrong.

  You can declare variables for while loop, this variable will be treated as local variables within the loop.

  If the variable is declared in the method and in the body of the loop method also declare variables with the same name as an error this variable, because the variable has been declared in a method, while the interior of the loop variable Although the local variable, but for the method body, the body of the loop variable variables and methods of the body in the same scope it is not allowed to have the same name.

  But you declare variables at the class level in such a method, while the body and declare variables such level variable with the same name, as may be used to distinguish them classname.indentifier.

  constant:

  The constant presence of a kind of "invariants" that once defined initialization can not be changed by the const keyword statement, the constant physical presence is a modified static, but in fact you are not allowed to modify it to use static, it is implied static, no static also not allowed to be modified.

  There is a constant fact in order to facilitate understanding, but also to avoid errors!

  Value types and reference types:

  Value is directly stored value types, the type of the value stored in the stack directly. Reference types are stored in a reference to the copied object, the object is stored in the managed heap. Their difference is that:

  They both exist independently of the value type variable to another value type, that there will be two identical data in memory, they are not linked, a change will not be another change occurs.

  Reference types are stored in reference to them, it can be said store address. Change one another also changed, because they point to the same object on the heap. Like create our own class is a reference type, if you want to create a type is defined as struct value type then use it.

  .NET type

  In fact, has its own .NET data types, the compiler will map the data types defined by the C # .NET, there are great similarities but there are also significant differences, for example: C # int in 32-bit and always. NET will need to be determined according to the operating system.

  After the knowledge I will not go into detail, it is worth mentioning are:

  1) so plastic types support decimal and hexadecimal, hexadecimal with 0x as a prefix.

  2) C # 7 supports an underscore _ partition, but does not support an underscore front support underlined prefixes after 7.2

  3) may be represented as a binary integer used 0b, but only the value of a combination of 0 and 1.

  . 4) provides a number of C # data types float floating type using a single-precision double suffix f 7 15/16 bit double precision accuracy using precision d, special note C # as the decimal data type is used exclusively financial calculation used for accuracy of 28 m using the identifier as a suffix.

  5) Like Java string as a special data type, it is a reference to the type of data types, but the difference is when it is assigned to another string data type, Talia point to the same object heap, when it was reassigned when will re-establish a new object heap address then give it. So string string is unique.

  6) C # use. "" There are internal to use the escape character string rather than have it as an escape character properties, that is mandatory as a string. $ "" Character string can be inserted the value (variable) but requires the use of variable curly braces {} package. example:

    “c:\\abc\\file.cs”等同于@“c:\abc\file.cs”     ||     string a="abc";  Console.WriteLine("a is {1} ",a);  等同于 Console.WriteLine($"a is {a}");

Finally, attach the digital literals table:

    Literals         position                      Explanation              
The suffix Unsigned unsigned
L suffix Long integer long
UL suffix Unsigned long int unsigned long
F suffix float float
M suffix Decomal currency type
0x Prefix Hexadecimal number
0b Prefix Binary number
true NA Boolean True
false NA Boolean value false

  

Guess you like

Origin www.cnblogs.com/js957/p/11111922.html