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

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(); 
主站蜘蛛池模板: 基隆市| 运城市| 鹤庆县| 邢台县| 大城县| 祁门县| 顺昌县| 海丰县| 铁岭市| 喀什市| 聂拉木县| 灵寿县| 会东县| 松阳县| 西乡县| 长阳| 陆河县| 丘北县| 乌鲁木齐市| 吉木萨尔县| 南雄市| 奎屯市| 措美县| 大邑县| 江永县| 沽源县| 台州市| 洪洞县| 云南省| 海伦市| 曲松县| 昆山市| 长寿区| 星座| 洞口县| 观塘区| 济源市| 那曲县| 长治县| 利辛县| 江津市|