A few days ago, the nullable type was suddenly used. Because it was rarely used, I forgot how to use it. I checked the relevant information and summarized it as follows (refer to msdn ). 1. The nullable type is a structure: system. nullable <t>. The writing format is t ?. T indicates any value type. 2. The nullable type adds an extra value for the original T: "null ". This is quite useful. For example, the checkbox status has three states: checked, unchecked, and indeterminate. Bool is not enough, so the nullable type can be used at this time: bool ?. 3. Two very useful read-only attributes of the nullable type: hasvalue and value. For example, if (X. hasvalue) {Y = x. value;} 4. OPERATOR :??. It means that if the value of the nullable type instance is null, it will be given a non-null default value. Let's look at the following example: Int? X = NULL; int y = x ?? -1; 5. The getvalueordefault function is also very useful. 6. Boxing and unboxing problems.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.