C # in Depth (fourth nullable type)

Source: Internet
Author: User

4.1 What to do if there is no value

You want to set the datetime variable to NULL, but the compiler does not allow (a product has not been sold yet, there is no date of purchase)

4.1.1 Why a variable of value type cannot be null

For a variable of a reference type, its value is a reference, and the value of a value type variable is its own real data. It can be assumed that a non-null reference value provides a way to access an object. However, NULL is equivalent to a special value, which means that I do not reference any object.

4.1.2 Mode in c#1.0 that represents null values

  • Magic Value (Datetime.minvalue)
  • Reference type Wrapper
  • Extra Boolean flag

4.2 System.nullable<t> and System.Nullable

Static Class System.nuallable provides a number of tool methods that simplify the use of nullable types.

4.2.1nullable<t> Introduction

Nullable<nullable<int>> is not allowed, even if the nullable<t> conforms to all characteristics of the value type in other respects. For any specific nullable type, the type of T is called the underlying type of the nullable type (underlying type). For example, the underlying type of,nullable<int> is int.

C # in Depth (fourth nullable type)

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.