C # 5.0

Source: Internet
Author: User

The five features that C # 5.0 will bring are published in2011-05-24 09:13| 8,059 reads | source Blog Park | Reviews | author Zhou Lihua Textboxasp.net extension c#5.0 Summary:The author compares C # 5.0 with previous versions, summarizes the new features of C # 5.0 for your reference.

Introduction: Author Zhou Lihua in the blog Park wrote a "C # 5.0 first-Glance", the author of C # 5.0 with the previous version of the comparison, summed up the C # 5.0 several new features for your reference.

First: The binding operator,: =:

This simply simplifies data binding, as is the case with the ASP. NET MVC3, which is not really a bright spot to improve.

Combobox1.text: =: TextBox1.Text; Binds the contents of the text box to a drop-down box.

Second: A generic constructor with parameters:

This addition to some of the design adds a powerful function, generics early in c#2.0 after the addition of a powerful application, generally slightly design a better framework, will be used to generics, c#5.0 added with parameter generic constructor, on the original basis on the C # generic perfect a lot. :)

public class T Myclass:t: Class, New ()

We might have

public class T Myclass:t:class, new (int)

Third: Supports NULL type operations:

This feature, personally feel is not a big highlight, but at least for the null type, especially with the data calculation of this type of NULL support, writing code is still a lot easier.

Note For nullable Types, the c#2.0 is added, but the calculation is not supported, such as:

Int? x = null;

Int? y = x + 40;

So what is the Y value? Do not support the calculation, get is null, presumably you know why the result is null? But c#5.0 can, 40 plus a null integer, we want the result is 40, but the part?

int x? = NULL;

int y? = x + 40;

Myobject obj = null;

Myotherobj obj2 = obj. MyProperty??? New Myotherobj ();

IV: Case Support expression:

This is a I very early thought if can be so good, did not expect to join this function in c#5.0, before case can only write a specific constant, and now can add expression, more flexible.

Switch (myobj) {

Case String. IsNullOrEmpty (myotherobj):

Logic code

Case Myotherobj. Trim (). Lower:

Logic code

}

Five: Extended properties.

We have an extension in the c#3.0, then in the c#5.0 will be added to the extended attribute of the concept, against the extension method, it is not difficult to understand the concepts of extended attributes. The following is an example of an extended attribute definition:

[Associate (String)]

public static int Zivsoft_extensionproperty {Get;set;}

c#5.0 is far more than the 5 new features described above, it is like c#4.0 joins the concept of dynamic, will join the concept of asynchronous processing, this is not a few lines of code can express, but will be in the design, architecture, will be a leap forward ...

For everyone to see first, give a c#5.0 a simple code example of asynchronous operation, note (c#5.0 Two new keywords async, await):

Task<movie> Getmovieasync (string title);

Task playmovieasync (movie movie);

Async void Getandplaymoviesasync (string[] titles)

{

foreach (var title in titles)

{

var movie = await Getmovieasync (title);

Await Playmovieasync (movie);

}

}

Original link: C # 5.0 First glance

C # 5.0

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.