Summary of the blog series of "understanding the new features of C #3. X"

Source: Internet
Author: User

Compared with C #2.0, C #3. X introduces a series of new features, which bring great convenience to our programming. By effectively utilizing these new features, we can compile more concise and elegantProgram. However, these new features are just a trick for the compiler: add some necessary code during compilation, from the perspective of C #2.0, the code that seems to be "incomplete" becomes "complete". In fact, the final assembly generated is not essentially different from that in the C #2.0 era. For this reason, some people disagree with these new features and feel that they are only superficial.Article. But my point is: since these features can bring us convenience, why not?

The focus of this series is not to apply these new features (in fact, it is very simple to use these features), but to introduce the implementation of these features more: what additional does the compiler add during compilation?CodeTo improve these slightly incomplete code.
[Article 1st]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:

1:VaR v =New{Id = guid. newguid (), name ="Zhang San"};


[Article 2nd]Extension Method
With the extension method, we can extend the method member without changing the definition of the type: In another type, we define the static method of one feature to serve as the extension 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.


[Article 3rd]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.


[Article 4th]Automatically impemented Property

With the automatically implemented property, we can simplify the attribute definition of the traditional private field + public property, just like this:

1: Public ClassVector


3:Public DoubleX {Get; set ;}

4:Public DoubleY {Get; set ;}



[Article 5th]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:

1:Vector v =NewVector {x = 1, y = 2 };

2:Ilist <String> List =NewList <String> {"Zhang San","Li Si","Wang Wu"};

Author: artech
The copyright of this article is shared by the author and the blog Park. You are welcome to repost this article. However, you must retain this statement without the author's consent and provide a clear link to the original article on the article page. Otherwise, you will be held legally liable.

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: 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.