At NDC London, Mads Torgersen proposed a plan for the future C # language. It is important to note that these are only plans and will not guarantee which version is released. Damien Guard Summary and brief analysis of these recommendations, we have selected some of the content here.
Read-only properties
Read-only automatic properties will allow developers to declare properties and their background fields in a single line of code.
public int X {get;} = x;
Static type using statement
Both Visual Basic and Java allow modules to be imported in namespaces (C # static classes). This removes the duplicate code in front of the usual static function, such as "Math."
Main constructor
By adding parameters to the class name, developers will no longer need to explicitly create constructors. This removes the verbose code when copying the constructor arguments to a private field.
public class point (int x, int y) { private int x, y;}
Property and Method expressions
Property expressions can eliminate some of the original boilerplate code that is necessary for a simple read-only property.
public double Distance = MATH.SQRT ((x * x) + (Y * y));
Method expressions are the same, and of course they can accept parameters. Note that the parameterized attribute is still not considered within the scope. In the future for quite a long time, this can only be VB unique features.
function parameters
Most developers today never use arrays unless they are using the params keyword. It was therefore suggested that the params also support the IEnumerable interface. If you do this, other languages, such as visual Basic, also need support. It has also been suggested that local variables can be declared using the Out keyword. For example
Int. TryParse ("123", out int x);
Air propagation
When dealing with messy data, developers often need to write a series of empty judgment logic before reading a property or calling a method. The syntax will help us to remove the logic, and the subsequent method will be called only if the value in front of it is not null.
var bestvalue = points?. FirstOrDefault ()?. X
In this example, if points is empty, or points. FirstOrDefault () returns NULL, it is ignored. X, and returns NULL. It can also and?? The connection is used to provide an optional default value.
var bestvalue = points?. FirstOrDefault ()?. X?? -1;
The "messaging" language, such as Objective-c and Smalltalk, contains such syntax. It is often considered problematic because it should have thrown a null reference to the exception, but was silently ignored.