.NetCore~C#6的一些新特性


回到目錄

在進行.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,我們繼續

 回到目錄


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM