Extended expression bodied members list C# with Example



Extended expression bodied members list C# with Example

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 
// setters 
set => names[id] = value; 
} 
} 
 

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

0 Comment's

Comment Form

Submit Comment