官术网_书友最值得收藏!

How to do it...

  1. 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");
}
}
  1. 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");
}
主站蜘蛛池模板: 宁化县| 永年县| 西华县| 浦东新区| 和政县| 洪泽县| 张家界市| 女性| 奈曼旗| 贵港市| 夏河县| 昌吉市| 应用必备| 平顶山市| 年辖:市辖区| 方正县| 东莞市| 延安市| 嘉黎县| 三台县| 巩义市| 大冶市| 治县。| 金乡县| 黑龙江省| 浮山县| 封丘县| 多伦县| 沙湾县| 东方市| 砀山县| 怀来县| 屏东县| 台山市| 剑川县| 繁峙县| 宾阳县| 潜江市| 平乡县| 田东县| 成都市|