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

推薦閱讀
- Java Web開發(fā)學(xué)習(xí)手冊
- Python測試開發(fā)入門與實踐
- Building Mobile Applications Using Kendo UI Mobile and ASP.NET Web API
- Kinect for Windows SDK Programming Guide
- Elasticsearch for Hadoop
- RabbitMQ Cookbook
- 西門子S7-200 SMART PLC編程從入門到實踐
- Arduino可穿戴設(shè)備開發(fā)
- PHP 8從入門到精通(視頻教學(xué)版)
- Learning Unreal Engine Game Development
- Go Systems Programming
- 例說FPGA:可直接用于工程項目的第一手經(jīng)驗
- Extending Docker
- Android應(yīng)用開發(fā)攻略
- C語言編程魔法書:基于C11標準