LINQ Learning (2). NET 3.X New Features review

Source: Internet
Author: User
Tags modifiers new features

The "C # 3.0 new features" are described earlier, and there is not much to be said about them, but in this way, a review of the new features of. NET 3.X.

Auto Property (Automatic properties)

It is useful to say that the property before the automatic property is a traditional attribute. Automatic properties simplify syntax, but also lose the ability to manipulate property settings when they are acquired, and to set initial values.

If you want to read-only or write-only, you can add an access modifier to a set or get, the access modifiers you set must be lower than the accessibility of the property itself, and you cannot set the access modifiers for both get and set; internal and protected intersect. Therefore, you cannot set properties and get or set separately for internal and protected.

The following code demonstrates automatic properties and traditional properties:

public class Test1
{
  public int Int0 { get; set; }
  public int Int1 { private get; set; }
  private int int2;
  private int int3;
  public int Int2
  {
    get { return int2; }
    set { int2 = value; }
  }
  public int Int3
  {
    get { return int3; }
  }
}

After compiling, use ILDasm view as shown:

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.