New nullable type in. NET 2.0

Source: Internet
Author: User
In. NET 2.0, there is a new nullable type, which can be used to assign null values to the basic value type, such

Int? K = 3; // a value type that can be empty (empty for short)
Int M = NULL; // Error
Int? J = NULL; // success
From the above example, we can see that a value type that can be empty can be defined after the value type. in C #, is a value type added after the basic type? In VB. NET

DimDtmvarnameAsNullable (OfDatetime)

DimIntvarnameAsNullable (Of Integer)

DimBvarnameAsNullable (Of Boolean)

Note that the null type is not a new. NET data type.
In fact, the empty type is defined in the. Net Library as a type class system. nullable <t>, where T is the value type that can be replaced.
Int? K = 3; similarly, you can write system. nullable <int> K = 3;
The operations are implemented through the operator overloading of this class.

You can use hasvalue to determine whether the null type has been assigned a value.

If(Dtmvarname. hasvalue)

{

//... Do something

}

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.