. 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