C# Language 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.