Summary of C #3. x's new feature series

Source: Internet
Author: User
1. Anonymous Type

Anonymous Type allows us to define an object and initialize a group of arbitrary attribute lists. The Type of this object is not pre-defined. For example:

Var v = new {ID = Guid. NewGuid (), Name = "Zhang San "};

2. Extension Method

With E xtension Method, we can extend the Method member without changing the definition of Type: we define a Static Method with one feature in another Type, make it the E xtension Method of this Type. This Method can be called like other methods. The Operator of LINQ, such as Where, From, and Order by, are defined in this way.

 3. Lambda Expression

Lambda expressions are widely used in LINQ. In essence, Lambda expressions are Delegate. In this section, I will introduce how Lambda expressions are implemented through a Delegate.

4. Automatically Impemented Property

With the Automatically Implemented Property, we can simplify the attribute definition of the traditional private field + public property, just like this:

Public class Vector {
Public double X {get; set ;}
Public double Y {get; set ;}
}

5. Object Initializer & Collection Initializer

Object Initializer & Collection Initializer combines Object creation and initialization into one: creates an Object and initializes its attribute members through an Object Initializer call at a time, use Collection Initializer to initialize the initial members of the Collection object when creating the Collection object:

Vector v = new Vector {X = 1, Y = 2 };

IList <string> list = new List <string> {"Zhang San", "Li Si", "Wang Wu "};

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.