- 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");
}
推薦閱讀
- 小程序?qū)崙?zhàn)視頻課:微信小程序開發(fā)全案精講
- LabVIEW2018中文版 虛擬儀器程序設(shè)計(jì)自學(xué)手冊(cè)
- OpenCV實(shí)例精解
- 動(dòng)手玩轉(zhuǎn)Scratch3.0編程:人工智能科創(chuàng)教育指南
- C/C++算法從菜鳥到達(dá)人
- Linux網(wǎng)絡(luò)程序設(shè)計(jì):基于龍芯平臺(tái)
- OpenShift在企業(yè)中的實(shí)踐:PaaS DevOps微服務(wù)(第2版)
- ArcGIS By Example
- 飛槳PaddlePaddle深度學(xué)習(xí)實(shí)戰(zhàn)
- MATLAB for Machine Learning
- 低代碼平臺(tái)開發(fā)實(shí)踐:基于React
- C語言程序設(shè)計(jì)上機(jī)指導(dǎo)與習(xí)題解答(第2版)
- MATLAB GUI純代碼編寫從入門到實(shí)戰(zhàn)
- Orleans:構(gòu)建高性能分布式Actor服務(wù)
- C++服務(wù)器開發(fā)精髓