- Mastering Visual Studio 2017
- Kunal Chowdhury
- 124字
- 2021-07-15 17:26:39
Changes to the expression-bodied members
In C# 6.0, Microsoft introduced the expression-bodied methods and properties, but these had a few limitations, which didn't allow us to use them in the constructors, destructors, and getters/setters of properties.
With C# 7.0, these limitations are no more, and you can now write them for single-liner constructors and destructors, as well as the getter and setter of a property. Here's how you can use them:
public class Person { private string m_name; // constructor public Person() => Console.WriteLine("Constructor called"); // destructor ~Person() => Console.WriteLine("Destructor called"); // getter/setter properties public string Name { get => m_name; set => m_name = value; } }
When you run the preceding code, the following output can be seen in the console window:

推薦閱讀
- PHP動(dòng)態(tài)網(wǎng)站程序設(shè)計(jì)
- Java入門經(jīng)典(第6版)
- 移動(dòng)UI設(shè)計(jì)(微課版)
- Python量化投資指南:基礎(chǔ)、數(shù)據(jù)與實(shí)戰(zhàn)
- Learn Swift by Building Applications
- Windows Server 2012 Unified Remote Access Planning and Deployment
- Internet of Things with Intel Galileo
- 單片機(jī)C語(yǔ)言程序設(shè)計(jì)實(shí)訓(xùn)100例
- Express Web Application Development
- Microsoft Dynamics AX 2012 R3 Financial Management
- Visual FoxPro程序設(shè)計(jì)習(xí)題及實(shí)驗(yàn)指導(dǎo)
- Java面試一戰(zhàn)到底(基礎(chǔ)卷)
- Android熱門應(yīng)用開發(fā)詳解
- Improving your Penetration Testing Skills
- Mastering React Test:Driven Development