首页 > Windows开发 > 详细

c# 6.0 特性

时间:2020-06-02 19:11:54      阅读:39      评论:0      收藏:0      [点我收藏+]

前言

迁移以前的笔记。

正文

只读属性初始化

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 testList = null;

static Test defaultList = testList?[0];

箭头方法

public void ConsolePrint(string msg) => Console.WriteLine(msg);

后续补齐c# 6.0 全部

c# 6.0 特性

原文:https://www.cnblogs.com/aoximin/p/13032973.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!