Essential C# C# 7.0 Features  Suggest an edit

Extended expression bodied members list

C# 7.0 adds accessors, constructors and finalizers to the list of things that can have expression bodies:

class Person
{
    private static ConcurrentDictionary<int, string> names = new ConcurrentDictionary<int, string>();

    private int id = GetId();

    public Person(string name) => names.TryAdd(id, name); // constructors

    ~Person() => names.TryRemove(id, out _);              // finalizers

    public string Name
    {
        get => names[id];                                 // getters
        set => names[id] = value;                         // setters
    }
}

Also see the out var declaration section for the discard operator.


Table Of Contents
22 Enum
25 GUID
70 C# 7.0 Features
107 Stream
108 Timers
  ↑ ↓ to navigate     ↵ to select     Esc to close