官术网_书友最值得收藏!

Changes to the throw expression

The earlier versions of C# had some limitations on throwing exceptions from certain places, which caused developers to write more code to validate and raise exceptions. In C# 7.0, those limitations have been removed to reduce the overload.

The Null Coalescing operator now allows you to throw an exception in the middle of the expression without explicitly checking for null:

    m_designation = designation ?? 
          throw new ArgumentNullException(designation); 

It is now possible to throw an exception from the Conditional operator too:

    m_department = department == null ?  
           throw new ArgumentNullException(department) :  
           department; 

C# 7.0 also allows you to throw an exception from expression-bodied member, as shown in the following code snippet:

    public void SetSalary(double salary) =>  
           throw new NotImplementedException(); 
主站蜘蛛池模板: 南汇区| 石屏县| 九寨沟县| 海盐县| 奈曼旗| 宜兰市| 苗栗市| 万安县| 淮安市| 镇安县| 罗源县| 红安县| 阿鲁科尔沁旗| 萍乡市| 萨迦县| 友谊县| 盐边县| 门头沟区| 梅河口市| 缙云县| 新源县| 淮安市| 北碚区| 黄浦区| 驻马店市| 绿春县| 靖西县| 榕江县| 澳门| 四平市| 洛南县| 大连市| 阳春市| 富源县| 平乡县| 嘉定区| 永嘉县| 阳泉市| 阜城县| 色达县| 崇左市|