- 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");
}
推薦閱讀
- 軟件安全技術(shù)
- PyTorch自動駕駛視覺感知算法實戰(zhàn)
- .NET 4.0面向?qū)ο缶幊搪劊夯A(chǔ)篇
- Python測試開發(fā)入門與實踐
- Learning AWS Lumberyard Game Development
- Git高手之路
- 深入理解Java7:核心技術(shù)與最佳實踐
- Ray分布式機器學(xué)習(xí):利用Ray進行大模型的數(shù)據(jù)處理、訓(xùn)練、推理和部署
- Bootstrap Essentials
- Java 11 Cookbook
- 可解釋機器學(xué)習(xí):模型、方法與實踐
- HoloLens與混合現(xiàn)實開發(fā)
- Python Machine Learning Cookbook
- Java Hibernate Cookbook
- 深入理解Kafka:核心設(shè)計與實踐原理