文章出處
文章列表
在進行.netCore平臺后,由于它的版本在.net4.6,C#6之后,所以它的語法也有一些新的特性,主要表現在以下幾個方面
只讀屬性初始化
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<Test> testList = null; static Test defaultList = testList?[0];
方法-單行實現
public void ConsolePrint(string msg) => Console.WriteLine(msg);
感謝各位的閱讀與支持!
.NetCore,我們繼續
文章列表
全站熱搜