In C# 6.0 I can write:
public int Prop => 777;
But I want to use getter and setter. Is there a way to do something kind of the next?
C# 7 brings support for setters, amongst other members:
More expression bodied members
Expression bodied methods, properties etc. are a big hit in C# 6.0, but we didn’t allow them in all kinds of members. C# 7.0 adds accessors, constructors and finalizers to the list of things that can have expression bodies:
class Person { private static ConcurrentDictionary
names = new ConcurrentDictionary (); 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 } }