- 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");
}
推薦閱讀
- Learning LibGDX Game Development(Second Edition)
- 構(gòu)建移動(dòng)網(wǎng)站與APP:HTML 5移動(dòng)開發(fā)入門與實(shí)戰(zhàn)(跨平臺(tái)移動(dòng)開發(fā)叢書)
- Mastering Natural Language Processing with Python
- React Native Cookbook
- 新手學(xué)Visual C# 2008程序設(shè)計(jì)
- Mastering C# Concurrency
- Web Application Development with MEAN
- AppInventor實(shí)踐教程:Android智能應(yīng)用開發(fā)前傳
- 編程可以很簡單
- .NET 4.5 Parallel Extensions Cookbook
- IDA Pro權(quán)威指南(第2版)
- Angular應(yīng)用程序開發(fā)指南
- PHP+MySQL動(dòng)態(tài)網(wǎng)站開發(fā)從入門到精通(視頻教學(xué)版)
- Visual FoxPro程序設(shè)計(jì)習(xí)題及實(shí)驗(yàn)指導(dǎo)
- HTML5程序設(shè)計(jì)基礎(chǔ)教程