Expression-bodied accessors, constructors, and finalizers

If the following expression looks intimidating, it's because it is using a feature introduced in C# 6 and expanded in C# 7:

private HashSet<string> AllowedExtensions => new HashSet<string>(StringComparer.InvariantCultureIgnoreCase) { ".doc",".docx",".pdf", ".epub" }; 
private enum Extention { doc = 0, docx = 1, pdf = 2, epub = 3 } 

The preceding example returns a HashSet of allowed file extensions for our application. These have been around since C# 6, but have been extended in C# 7 to include accessors, constructors, and finalizers. Let's simplify the examples a bit.

Assume that we had to modify the Document class to set a field for _defaultDate inside the class; traditionally, we ...

Get C# 7 and .NET Core 2.0 Blueprints 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.