1, nullable type modifier (?) : A reference type can use a null reference to represent a nonexistent value, and a value type is usually not represented as empty, for example: string str=null; is correct. int i=null; The compiler will make an error. For a value type to be nullable, a nullable type appears, and a nullable type uses a nullable type modifier to indicate that the representation is T? For example: int? is a nullable shaping, DateTime is expressed as a nullable time. T? is actually an abbreviated form of system.nullable<t> (generic structure), which means that when you use T, the compiler compiles the t into a system.nullable<t> form, for example: int? After compiling is the form of system.nullable<int>.
Copy Code code as follows:
int A; A<>null
int? b; B=null
int? c = b+1; C=null;
2, empty merge operator (??) : Used to define the default values for nullable types and reference types. If the left-hand operand of this operator is not NULL, the operator returns the left operand, otherwise the right-hand operand is returned. Example: A?? b, when a is null, returns the b,a when it is not empty. The null merge operator is the right binding operator, which is a combination of right-to-left and right-to-left operations. such as, "a??" B?? C "In the form of" a?? (b??) c) "calculation.
Copy Code code as follows:
Int?a=null; int b; (declarations A and B)
B=a?? 2; b=2;
A=6;b=a?? 8;//b=6;
3, ternary (operator) expressions (?:) : If this you do not understand the words (I do not believe), then you should not understand it, no longer repeat.
Copy Code code as follows: