New features in VS2015 C #6.0,

Source: Internet
Author: User

New features in VS2015 C #6.0,

VS2015 has been installed on its own machine. (if it is all installed, it will take a long time to get stuck in the Java SE Development Kit. I will close it directly, restart the computer, and fix and install it again ),

I want to experience the cross-platform experience. The result is a hit by Microsoft. It is still useless to install it. I should also install the Xarmain plug-in and configure some parameters,

Since this item has never been used before, I want to continue to waste my time here, so I can try new features.

References:

1: CHS-WhatsNewinC #6.0 (Microsoft Video) Link: http://pan.baidu.com/s/1kTjLyjt password: v6mr

2: VS2015CSharp6.0 (English document) Link: http://pan.baidu.com/s/1eQsddtC password: kvg1

1. Automatic attribute Enhancement

1.1. Initializers for auto-properties)

C #5.0 cannot be implemented.

C #6.0 automatic attribute Initialization Method

1.2 read-only attributes initialize Getter-only auto-properties

Let's take a look at the method we used before.

Let's take a look at C #6.0.

It is consistent with the first automatic attribute initialization method.

2. Reference Static class Using Static

You can specify a static class in Using, and then you can directly use static members in subsequent code.

3. String embedding Value

The method used to embed values in strings is

 

Now we can simply splice the data as follows:

4. Expression bodied function members

4.1 Use Lambda as the function body Expression bodies on method-like members

4.2 Use Lambda expressions as the attribute Expression bodies on property-like function members

5. Index initializers, the object initializers with indexes

6. Null-conditional operators

7. nameof expression nameof expressions

During the method parameter check, you may often see such code (less used before, this time also learned)

The Point is a handwritten string. When we rename the Point, it is easy to forget the string below. C #6.0 nameof helps us solve this problem and look at the new writing method.

8. Exception filters)

Let's look at a porting method.

1 try {var numbers = new Dictionary <int, string> {[7] = "seven", [9] = "nine", [13] = "thirteen "}; 2} catch (ArgumentNullException e) 3 {if (e. paramName = "customer") 4 {5 Console. writeLine ("customer can not be null"); 6} 7}Porting Method

The Microsoft document also provides another usage. This exception will be thrown to the caller at the previous layer when the log record fails.

1 private static bool Log (Exception e) 2 {// process some logs return false; 3} static void Main (string [] args) 4 {try {//} catch (Exception e) {if (! Log (e) 5 {6 7} 8} 9 10 Console. ReadLine (); 11}Microsoft's document handling exception

9. await in catch and finally -- Await in catch and finally blocks

In C #5.0, The await keyword cannot appear in catch or finnaly blocks. In 6.0

1 try {2 res = await Resource. OpenAsync (...); // You cocould do this .... } Catch (ResourceException e) 3 {await Resource. LogAsync (res, e); // Now you can do this... } Finally {if (res! = Null) await res. CloseAsync ();//... And this .}C #6.0 await

10. Parameterless constructors in structs, a struct without Parameters

Summary:

I have seen an article published by a big God. It feels good. I also learned a lot of new things.

References:

Http://aehyok.com/Blog/Detail/66.html

Http://jingyan.baidu.com/article/54b6b9c0df22742d593b476d.html

 

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.