This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19619|Reply: 0

[Communication] int in C#? Explanation

[Copy link]
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
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com