|
|
Posted on 2/19/2019 11:30:04 AM
|
|
|

nt? : represents a nullable type, which is a special value type, and its value can be null Used to assign a value to a variable (int type) as null instead of 0 when setting the initial value to a variable int?? : Used to judge and assign values, first determine whether the current variable is null, if so, you can assign a new value, otherwise skip it
A question mark after the value type indicates that it can be null (Nullable structure)
Nullable is a new technique in .NET 2.0 for indicating whether a value type can be null.
For a type, if you can assign it either a value or a null reference null (meaning there is no value), then we say that the type is nullable.
Therefore, a null type can represent a value, or indicate that no value exists. For example, a reference type like String is a nullable type, while a value type like Int32 is not a nullable type. The Nullable structure supports extending value types to be null, but not on reference types, which are inherently nullable.
Because the value type has enough capacity to represent a value suitable for that type, it cannot be null; The value type does not represent the additional capacity required for a null value.
For example: public int? age;
Supplement: The same is true for other types of post-addition questions. int? num = null; That's right int num=null; Wrong
|
Previous:Tuesday, February 19, 2019 (Happy Lantern Festival!) )Next:C# uses HttpClient for http operations GetStringAsync
|