. NetCore ~ Some new features of C #6,

Source: Internet
Author: User

. NetCore ~ Some new features of C #6,

After the. netCore platform is launched, because its version is later than. net4.6 and C #6, its syntax also has some new features, mainly in the following aspects:

 Read-only attribute Initialization

static string Hello => @"Hello world , Lind!"; //static string Hello{get;}

Attribute Initialization

 static DateTime AddTime { get; set; } = DateTime.Now;

Dictionary Initiator

      static Dictionary<string, string> dictionary1 = new Dictionary<string, string>        {            ["name"] = "lind",            ["age"] = "16"        };

String. Format, $ is introduced in the background, and smart prompts are supported.

Static string t2 = $ "time from {DateTime. Now} to {DateTime. Now. AddDays (1 )}";

Null Object judgment

 static Test test = new Test(); static string title = test?.Name;//if(test!=null) title=test.Name;

Null set judgment

 static List<Test> testList = null; static Test defaultList = testList?[0];

Method-single row implementation

 public void ConsolePrint(string msg) => Console.WriteLine(msg);

Thank you for your reading and support!

. NetCore, let's continue

 

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.