When I look at the MVC self-generated example today, C # has two strange question marks:
Public accountcontroller (iformsauthentication formsauth, imembershipservice Service)
{
Formsauth = formsauth??New formsauthenticationservice ();
Membershipservice = Service??New accountmembershipservice ();
}
Search online, summarized as follows:
1. Can be empty type modifier (?) :
The reference type can use null reference to indicate a nonexistent value, while the value type cannot be null.
For example, string STR = NULL; is correct, int I = NULL; the compiler reports an error.
To make the value type empty, you can use the void type, that is, the void type modifier "? "T? "
Example: Int? It indicates an integer that can be null, datetime? It indicates a time that can be empty.
T? It is actually the abbreviation form of system. nullable <t> (generic structure), that means when you use t? When the compiler compiles t? Compiled into the form of system. nullable <t>.
Example: Int ?, After compilation, it is in the form of system. nullable <int>.
2. Ternary (operator) expression (? :):
Example: X? Y: Z indicates that if expression X is true, return Y. If expression X is false, return Z, which is a simple form of if {} else {} omitted.
3. null merge operator (??) :
Defines the default values of the null and reference types. If the left operand of this operator is not null, this operator returns the left operand; otherwise, the right operand is returned.
Example: ?? B returns B if A is null, and a itself if A is not null.
The null merge operator is the right merge operator, that is, the Union from right to left during the operation. For example, "?? B ?? C ?? (B ?? C) "computing.