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");
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.77.153