Empty type system. nullable

Source: Internet
Author: User

The Null Value in C # cannot be assigned to the value type. The value type here includes struct. The reason is that the value type cannot contain references. null, as a "none" reference, cannot be referenced by the value type. In actual application, this will cause some problems. If an int type cannot determine its value. An empty type is required.

The value type variable that can be assigned a null value. An empty type based on the reference type cannot be created. (The reference type supports null values .).

Int? : Indicates an empty type, which is a special value type. Its value can be null.
It is used to assign null to the variable (INT type) when setting the initial value, instead of 0.
Int ?? : Used to determine and assign values. First, judge whether the current variable is null. If yes, you can activate a new value. Otherwise, skip
Void main () {system. nullable <int> I = NULL; console. writeline (I. hasvalue); console. writeline (I); var T = I ?? 0; console. writeline (t); var S = (Int ?) NULL; // system. nullable <t> can be abbreviated as t ?, Console. writeline (s); console. writeline (I. GetType (); // exception console. writeline (I. Value); // exception}

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.