[Dry goods to attack] c#6.0 new Features

Source: Internet
Author: User

Microsoft released the new VS 2015 yesterday. And then there's a lot of stuff .... NET new version of ASP. NET new version ... Wait a minute.. Too many. Not really digested.

Share some new features of the new c#6.0 that were released yesterday ...

Of course.. I have not used--, mainly refers to a foreign one article. Very detailed, good English can see for themselves

Https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6

First of all

Automatic Property Initialization Enhancements
 Public class customer{    publicstringgetset"Jane" ;      Public string Get Set " Doe " ;}

 public  class   customer{ string  First {get ;} =  " jane   ;  public  string  last {get ; } =   "   
 Public class customer{   // read-only property   public    stringget;};     // Assignment in initialization method, feasible ~     public Customer (stringstring Last )    {        "" + last ;    }}

It is not feasible in c#5.0 such as:

The method function supports lambda notation as follows:
 Public void " " + last);
importing a static class directly, rather than using a static class name in your code, is supported for direct import of the namespace as follows:
//Static Import Consoleusing StaticSystem.Console;using StaticSystem.Math;using StaticSystem.dayofweek;classprogram{Static voidMain () {//direct use of the method without Console.WriteLineWriteLine (Sqrt (3*3+4*4)); WriteLine (Friday-Monday); }}
Extension method, (this is not very understand, explanation is not good please forgive)

In the main class, statically import the type you want to extend, and then write the method you need to extend:?.. --Don't understand.

using StaticSystem.Linq.Enumerable;//the type, not the namespaceclassprogram{Static voidMain () {varRange = Range (5, -);//ok:not Extension        varOdd = Where (range, i = i%2==1);//Error, not in scope        vareven = range. Where (i = i%2==0);//Ok    }}

The non-empty syntax sugar is as follows:
int? First = customers? [0]. Orders.count (); // the above notation is equivalent to the following int null) ? customers[0null;

String Formatting new gameplay:
//the original, we need this.vars = String.Format ("{0} is {1} year{{s}} old", P.name, p.age);//c#6.0, direct as follows:vars = $"{P.name} is {p.age} year{{s}} old";//it can even be arbitrary in {}: (Words do not: expression or what the hell. --,) anyway as follows:vars = $"{p.name,20} is {p.age:d3} year{{s}} old";vars = $"{P.name} is {p.age} year{(p.age = = 1? )"" : "S")} old";

Index initialization:
var New dictionary<intstring> {    [7"seven"  ,    [9"nine",    [+] Thirteen " };
Exception Filters:

If when the expression in parentheses evaluates to run in a True,catch block, the exception persists.

(--And yet I don't understand it.) Ask the great God to explain ...)

Try {...} Catch (MyException E) when (Myfilter (e)) {    ...}
Catch blocks that can be asynchronously awaited:
Resource res =NULL;Try{res=awaitResource.openasync (...);//You could does this ....} Catch(resourceexception e) {awaitResource.logasync (res, E);//Now the can do ...}finally{    if(Res! =NULL)awaitRes. Closeasync ();//... and this.}

This is basically the end,--the level is limited. Bad and imperfect place please point out. Lest you mislead us.

[Dry goods to attack] c#6.0 new Features

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.