Possible new features of C # 6.0
1. Main constructor (Primary constructors)
The main constructor assigns a value to a variable in a class
Before
public class Point { private int x, y; public point (int x, int y) this.x = x; This.y = y; }}
After
public class point (int x, int y) { private int x, y;}
2. Automatic attribute Assignment (auto properties)
before
Class Point {public int X {get; private set;} public int Y {get; private set;} Public Point () {this . X = +; This. Y = +; }
After
Class Point {public int X {get; private set;} = ; public int Y {get; private set;} = 100;
3. Using static class (static type using statements;)
Using will import all static methods of the reference class into the current namespace
before
Public double A {get {return math.sqrt (Math.Round (5.142));}}
After
Using System.math;...public double A {get {return Sqrt (Round (5.142));}}
4, Property Expressionsbefore
Public double Distance { get {return math.sqrt ((x * x) + (Y * y));}}
After
public double Distance = MATH.SQRT ((x * x) + (Y * y));
It looks like a lambda expression at first, and it's actually not related to lambda.
5. Method Expressionsbefore
Public point Move (int dx, int dy) { return new point (X + dx1, Y + dy1);}
After
Public point Move (int dx, int dy) = + new Point (X + dx, Y + dy);
This is similar to the property expressions.
6. Params for Enumerablesbefore
Do (Someenum.toarray ()), ... public void do (params int[] values) {...}
After
Do (someenum);p ublic void do (params ienumerable<point> points) {...}
Previously, the params was only able to modify the parameters of the array type, and now there are a number of types
7, monadic null checking (null check operator) before
if (points! = null) { var next = points. FirstOrDefault (); if (next! = null && next. X! = null) return to next. X;} return-1;
After
var bestvalue = points?. FirstOrDefault ()?. X?? -1;
This is a few lines of code, praise AH
8. Constructor type parameter Inferencebefore
var x = myclass.create (1, "X"); public myclass<t1, T2> create<t1, t2> (T1 A, T2 b) { return new MYCLASS&L T T1, T2> (A, b);}
After
var x = new MyClass (1, "X");
9. Inline declarations for out params (inline out parameter definition) before
int X;int. TryParse ("123", out X);
After
Int. TryParse ("123", out int x);
To tell the truth, this is very common.
Of course, all of the new features of C # 6.0 are more than that, and they are limited to space, so if you want to learn more, please refer to the links below.
Resources:
Http://roslyn.codeplex.com/wikipage?title=Language%20Feature%20Status&referringTitle=Documentation
Http://en.wikipedia.org/wiki/.NET_Framework_version_history
http://damieng.com/blog/2013/12/09/probable-c-6-0-features-illustrated
Http://www.kunal-chowdhury.com/2012/07/evolution-of-c-10-50-what-are-new.html
Http://www.cnblogs.com/TianFang/p/3647144.html
Possible new features of C # 6.0