.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,我们继续

 回到目录

posted @   张占岭  阅读(4632)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
历史上的今天:
2013-02-04 不说技术~我需要调整自己,最近整整两天状态不是很好
点击右上角即可分享
微信分享提示