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);





 

相关文章:

  • 2021-10-11
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2021-07-06
  • 2021-11-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
相关资源
相似解决方案