菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
139
0

c#6.0

原创
05/13 14:22
阅读数 67021

c#6.0

一.字符串嵌入值:

$代替stirng.Format

二.自动属性赋值:

public string Name { get; set; } = "summit";
三.使用静态类导入using static System.Math;
Math类:Math.方法
新用法:直接方法名即可

四.空值校验:
之前
string name=null;
name.Tostring()会报错
现在
name?.Tostring()不会报错
五.对象初始化器:
之前
IDictionary<int, string> dictOld = new Dictionary<int, string>()
{
        { 1,"first"},
        { 2,"second"}
};
现在
直接通过索引赋值
IDictionary<int, string> dictNew = new Dictionary<int, string>()
 {
         [4] = "first",
         [5] = "second"
 };
六.异常:
之前:
catch (Exception e)
现在:
 catch (Exception e) when (exceptionValue > 1)//满足条件才进入catch
 catch (Exception e) when (exceptionValue > 1)//满足条件才进入catch
七.在属性/方法里面使用Lambda表达式
 public string NameFormat => string.Format("姓名: {0}", "summit");
2 public void Print() => Console.WriteLine(Name);




 

发表评论

0/200
139 点赞
0 评论
收藏