Get the App
SLTechnology News&Howtos  ›  Servers  › 

"?" in C # There are three uses.

Shulou Source: shulou.com Published: 2022-06-03 03:45:38 09月22日 Update

1. Nullable type modifier (?): Reference types can use null references to represent a value that does not exist, while value types generally cannot be represented as null, e.g.:string str=null; is correct. int i=null; the compiler will report an error. In order to make value types nullable, nullable types appear, nullable types use nullable type modifiers? The expression is T?. Example: int? Is it empty ×××, DateTime? Time expressed as nullable. T? Nullable, which means that when you use T? T? T? Compile to System.Nullable, e.g. int?, After compilation, it is in the form of System.Nullable.

2, Triple (operator) expression (?:): For example, int a=b>0? 4:5 If b is greater than 0 then return a=4 otherwise a=5.

3. Empty merge operator (??): Default values for defining nullable and reference types. If the left operand of this operator is not null, the operator returns the left operand; otherwise, it returns the right operand. Example: A b, return b when a is null, return a itself when a is not null. The null merge operator is a right join operator, which combines from right to left when operating. For example,"a? b?? c"in the form of"a?? (b?? c)"Calculation.

Tags: Type operator operation form compilation Operand compiler meaning time structure abbreviation expression ternary combination C # Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Technology Xiaomi Redmi Docker