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

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");
}
主站蜘蛛池模板: 白河县| 大厂| 弋阳县| 台江县| 永胜县| 台南市| 新营市| 高台县| 图木舒克市| 山阴县| 博客| 富蕴县| 宜宾县| 寻乌县| 安平县| 尚志市| 阜新| 沙洋县| 措美县| 武宁县| 彰化市| 仪征市| 庆阳市| 龙岩市| 和顺县| 禹城市| 贡嘎县| 饶河县| 饶平县| 宣汉县| 天镇县| 方山县| 上犹县| 霍州市| 武城县| 陆丰市| 银川市| 玉屏| 宿松县| 武穴市| 南平市|