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

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(); 
主站蜘蛛池模板: 虹口区| 东丽区| 峨边| 肇源县| 青浦区| 乌鲁木齐县| 钟祥市| 临邑县| 永和县| 永年县| 白沙| 西城区| 喀什市| 灵川县| 新余市| 漳浦县| 鄂尔多斯市| 通江县| 娄底市| 稷山县| 长顺县| 来安县| 纳雍县| 溆浦县| 宝鸡市| 徐州市| 开远市| 芒康县| 乌什县| 皋兰县| 固安县| 沈阳市| 崇左市| 石景山区| 霸州市| 洮南市| 五台县| 进贤县| 三河市| 汉阴县| 长沙县|