This Wednesday night on the second section of C #, Mr. Zhang introduced some basic knowledge of C # in detail. Because most of them are similar to C++,java and so on, so I will not repeat them here, just a little bit to record some of the things I think are more important, error prone or not the same as other languages.
1. type conversion
In C #, the following assignment statement: A variable with a large value range = A variable with a small value range can be compiled, and a variable with a range of small values = a variable of a large value cannot be compiled. such as the following code:
1 Short x=5; 2 // Assignment statement: variable with a large value range = variablewith a small range;3// compile can pass, Y value is 5, implicit type conversion succeeds 4int y = x;
1 Short x; 2 int - ; 3 // Assignment statement: variable with a range of small values = variable with large range;4// compilation cannot pass, cannot complete implicit conversion, compiler Error 5
This is an implicit type conversion aspect, however it is possible to achieve the effect of an explicit type conversion to a variable with a range of small values, such as the following code:
1 Short x; 2 int - ; 3 // Assignment statement: A variable with a range of small values = A variable of a large value;4// can be compiled, the explicit conversion succeeds, but you need to pay attention to the scope of 5 x = ( Short
I think this kind of processing is very good, can effectively avoid the type conversion when the value overflow problem, reduce the probability of the bug.
2.
The basics of C # learning