c# 6.0 特性
阿新 • • 發佈:2020-06-03
前言
遷移以前的筆記。
正文
只讀屬性初始化
static string Hello => @"Hello world,Lind!"; //static string Hello{get;}
屬性初始化
static DateTime AddTime { get; set; } = DateTime.Now;
字典初始化
static Dictionary<string,string> dictionary1 = new Dictionary<string,string>
{
["name"] = "lind",
["age"] = "16"
};
string.Format,後臺引入了$,而且支援智慧提示
static string t2 = $"時間從{DateTime.Now}到{DateTime.Now.AddDays(1)}";
判斷物件是否為空
static Test test = new Test();
static string title = test?.Name;//if(test!=null) title=test.Name;
空集合判斷
static List
static Test defaultList = testList?[0];
箭頭方法
public void ConsolePrint(string msg) => Console.WriteLine(msg);