C #3.0 Get Set Default Value

Source: Internet
Author: User

I have previously introduced the default value of C #3.0 {Get; set;}. This article is based on it and adds some content.

. NET Framework 3.5 uses C #3.0, and C #3.0 has some new language features, one of which is quick attributes.

Previous statement:

Private int _ id = 0;
Public int ID
{
Get
{
Return _ id;
}
Set
{
_ Id = value;
}
}

C #3.0 can be abbreviated as follows:

Public int ID {Get; set ;}

C #3.0 {Get; set;} Default Value

This means the default value of {Get; set;} does not exist. We cannot manually specify the default value because the private self-segment does not exist. What is the default value of the system?

  • For int type, the default value is 0;
  • For Int? Type. The default value is null;
  • For the bool type, the default value is false;
  • For bool? Type. The default value is null;
  • For the string type, the default value is null;
  • For string? Type, haha. If this method is not used, errors may occur;
  • For the datetime type, the default value is 0001-01-01 00:00:00;
  • For datetime? Type. The default value is null;
  • For the enum type, the default value is 0. If there is no Enum item of 0, it is still 0. For more information, see C # enumeration (Enum );
  • For Enum? Type. The default value is null;
  • For the class type, the default value is the reference of an uninstantiated object;
  • For class? Type.

About type addition ?, Indicates that the value of this type can be null. For example, if int does not have a null value, add Int? It can be null.

Related Article

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.