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

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(); 
主站蜘蛛池模板: 万宁市| 天长市| 绥化市| 苍山县| 马鞍山市| 宣化县| 晴隆县| 彭水| 永靖县| 东安县| 临洮县| 苍南县| 甘洛县| 宁海县| 宜章县| 灵寿县| 闽清县| 建始县| 江孜县| 台湾省| 军事| 大洼县| 马龙县| 错那县| 扶绥县| 石家庄市| 双城市| 无锡市| 南昌市| 龙南县| 福安市| 梁山县| 汝城县| 兴化市| 云和县| 图木舒克市| 城口县| 米易县| 彭泽县| 宁陕县| 岳阳县|