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 ...

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.