- 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:

推薦閱讀
- ASP.NET MVC4框架揭秘
- SQL基礎教程(視頻教學版)
- SQL Server 2016數據庫應用與開發
- Learning Probabilistic Graphical Models in R
- AIRIOT物聯網平臺開發框架應用與實戰
- 微信小程序全棧開發技術與實戰(微課版)
- D3.js By Example
- OpenCV with Python By Example
- 汽車人機交互界面整合設計
- Oracle實用教程
- App Inventor少兒趣味編程動手做
- SQL Server 2008實用教程(第3版)
- 一步一步學Spring Boot:微服務項目實戰(第2版)
- JavaScript Unit Testing
- SQL Server 2014 Development Essentials