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

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(); 
主站蜘蛛池模板: 陇南市| 七台河市| 邳州市| 社旗县| 平舆县| 沭阳县| 吴旗县| 平昌县| 二连浩特市| 漳州市| 榆中县| 延寿县| 盐边县| 清河县| 滕州市| 扬中市| 南宁市| 东辽县| 望城县| 遂昌县| 隆昌县| 策勒县| 轮台县| 新平| 平乡县| 喀喇| 禄劝| 冕宁县| 策勒县| 德钦县| 白山市| 兴和县| 常熟市| 巴里| 丽江市| 临潭县| 淮阳县| 瑞昌市| 梅河口市| 沧源| 河南省|