- C# 7 and .NET Core 2.0 High Performance
- Ovais Mehboob Ahmed Khan
- 177字
- 2021-08-27 18:47:10
Expression bodied member extended
Expression bodied members were introduced in C# 6.0 where the syntactical expression of the method can be written in a simpler way. In C# 7.0, we can use this feature with a constructor, a destructor, an exception, and so on.
The following example shows how the constructor and destructor syntactic expressions can be simplified using expression bodied members:
public class PersonManager { //Member Variable Person _person; //Constructor PersonManager(Person person) => _person = person; //Destructor ~PersonManager() => _person = null; }
With properties, we can also simplify the syntactic expression, and the following is a basic example of how this can be written:
private String _name; public String Name { get => _name; set => _name = value; }
We can also use an expression bodied syntactic expression with exceptions and simplify the expression, which is shown as follows:
private String _name; public String Name { get => _name; set => _name = value ?? throw new ArgumentNullException(); }
In the preceding example, if the value is null, a new ArgumentNullException will be thrown.
推薦閱讀
- Spark快速大數(shù)據(jù)分析(第2版)
- Python金融大數(shù)據(jù)分析(第2版)
- Architects of Intelligence
- App+軟件+游戲+網(wǎng)站界面設(shè)計教程
- 卷積神經(jīng)網(wǎng)絡(luò)的Python實現(xiàn)
- 文本挖掘:基于R語言的整潔工具
- 數(shù)據(jù)庫系統(tǒng)原理及應(yīng)用教程(第4版)
- WS-BPEL 2.0 Beginner's Guide
- 數(shù)據(jù)庫技術(shù)及應(yīng)用教程
- Python數(shù)據(jù)分析與挖掘?qū)崙?zhàn)(第3版)
- 二進(jìn)制分析實戰(zhàn)
- Gideros Mobile Game Development
- 數(shù)據(jù)庫原理及應(yīng)用:SQL Server 2016
- AI Crash Course
- 大數(shù)據(jù)用戶行為畫像分析實操指南