C #6 new features and sample code,

Source: Internet
Author: User

C #6 new features and sample code,

Today we recommend a Github open-source project, but this open-source project specifically introduces the latest features of C #6 and provides sample code.

We know that Microsoft is about to release Windows 10 and Visual Studio 2015. The latest versions of C #6 and VB 14 will be available in VS2015. I think you should have learned more or less about some new features of C #6 in the early stage.

On the page recommended today (or on the website), Robert MacLean provides a series of blog addresses to introduce the new features of C #6 one by one, with sample code included. It involves the following new features of C #6:

  • Dictionary/Index Initialisers or Index Initialisers ). This feature makes initialization of dictionaries and list sets easier.
  • Auto-properties with initializers ). Previously, the automatic attribute initialization can only be performed in the constructor, and can now be written to the attribute.
  • Read-only auto-properties ). In fact, the previous C # supports the automatic attribute of implementing the read-only effect (making the set statement private), but now it can be truly supported.
  • Static using Statement (Static Using Statements ). By attaching a static modifier to using, you can omit the namespace and class prefix for static method calls.
  • Await (Await in catch blocks) is supported in catch fragments ). This feature is just as the name suggests.
  • Exception Filtering ). When an exception is caught, you can use additional Judgment conditions to filter whether the execution process enters the current catch segment. This feature has many clever tricks (for example, I used this feature to implement C # pattern matching ), the author also explained in detail the Additional Details on Exception Filtering ).
  • Null Value propagation operation or the nullet operator (Null Propogation (the nullet operator )). If an object may be empty before, you need to judge and access its attributes. Now you can use the nullet operator (or the maowang operator) "?." To quickly implement such code logic. This feature relies heavily on the functions of the Roslyn compiler.
  • Obtain the name string (NameOf ). This feature is similar to TypeOf, but NameOf obtains the name string value. With this feature, my mom will no longer have to worry about writing wrong names.
  • The member's internal code is written as an Expression (Expression Bodied Members ). That is, you can directly write the internal code of a method (such a class member) into an expression, so that a line of code can complete the compilation of the method.
  • String Interpolation ). Several variables need to be constructed as a string, except for string connection, which is string. Format. Now you can directly Insert the variable name in the string.

The content written in the above blog is very informative and easy to understand, with code. In particular, we will first describe how the C # Old Version completes similar work, and how to get twice the result after using the new syntax. It is a rare learning material for C #6's new features.

You can access the blog index and specific code by reading the original article.

Address: https://github.com/rmaclean/sharpsharpwithcsharp6

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.