Future plans for C #

Source: Internet
Author: User
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.

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