zoukankan      html  css  js  c++  java
  • C#6.0特性与vs2015

    C#6.0 中的那些新特性

    1. 自动属性的初始化

    public string Name { get; set; } = "zhangsan";

    2. 只读属性初始化

    public string Name { get; } = "zhangsan";

    3. 引用静态类Using Static

    using static System.Math;//    引用命名空间
    
    Abs(23);//    方法中调用Math.Abs绝对值的方式

    4. 字符串嵌入值

    var num = 25;
    $"数字是{num}"        //    结果:数字是25

    5. 用Lambda作为函数体

    public int GetSumValue() => 1 + 2;    //    等同于    public int GetSumValue(){    return 1 + 2;    }

    6. 用Lambda表达式用作属性

    public int Value => 1 + 2;            //    等同于    public int Value{    get{    return 1+2;    }}

    7. 带索引的对象初始化器Index initializers

    public Dictionary<string, object> Dics() => new Dictionary<string, object>() { ["name"] = "duanlaibao@benlai.com" };
    //    等同于
    public Dictionary<string, object> Dics()
    {
        Dictionary<string, object> Temp = new Dictionary<string, object>();
        Temp[“name”]= duanlaibao@benlai.com;
        return Temp;
    }

    8. 空值判断Null

    var model = new PushObject();
    model?.ID
    //    等同于
        var model = new PushObject();
        if (model != null)
        {
            model.ID
        }
  • 相关阅读:
    Transformer详解
    PAT 1012
    PAT 1011
    PAT 1010
    Jordan Lecture Note-3: 梯度投影法
    PAT 1009
    PAT 1008
    Jordan Lecture Note-2: Maximal Margin Classifier
    PAT 1007
    PAT 1006
  • 原文地址:https://www.cnblogs.com/licin/p/8081387.html
Copyright © 2011-2022 走看看