- C# 7 and .NET Core Cookbook
- Dirk Strauss
- 111字
- 2021-07-03 00:11:56
How to do it...
- Consider the class SomeClass. It contains a constructor, finalizer, and a property.
public class SomeClass
{
private int _initialValue;
// Property
public int InitialValue
{
get
{
return _initialValue;
}
set
{
_initialValue = value;
}
}
// Constructor
public SomeClass(int initialValue)
{
InitialValue = initialValue;
}
// Finalizer
~SomeClass()
{
WriteLine("Release unmanaged code");
}
}
- With expression-bodied members, the class SomeClass can be simplified and the number of lines of code reduced.
public class SomeClass
{
private int _initialValue;
public int InitialValue
{
get => _initialValue;
set => _initialValue = value;
}
public SomeClass(int initialValue) =>
InitialValue = initialValue;
~SomeClass() => WriteLine("Release unmanaged code");
}
推薦閱讀
- Qt 5 and OpenCV 4 Computer Vision Projects
- TensorFlow Lite移動端深度學習
- 兩周自制腳本語言
- 劍指Offer(專項突破版):數據結構與算法名企面試題精講
- Rake Task Management Essentials
- Scala程序員面試算法寶典
- Odoo 10 Implementation Cookbook
- .NET Standard 2.0 Cookbook
- SQL Server 2016 從入門到實戰(zhàn)(視頻教學版)
- HTML5+CSS3+JavaScript 從入門到項目實踐(超值版)
- Android Sensor Programming By Example
- MyBatis 3源碼深度解析
- 寫給青少年的人工智能(Python版·微課視頻版)
- 實戰(zhàn)Python網絡爬蟲
- 關系數據庫與SQL Server 2012(第3版)