Chapter 8. Super-sleek properties and expression-bodied members
This chapter covers
Some versions of C# have one big, unifying feature that almost all other features contribute to. For example, C# 3 introduced LINQ, and C# 5 introduced asynchrony. C# 6 isn’t like that, but it does have a general theme. Almost all the features contribute to cleaner, simpler, and more readable code. C# 6 isn’t about doing more; it’s about doing the same work with less code.
The features you’ll look at in this chapter are about properties and other simple pieces of code. When not much logic is involved, removing even the smallest piece of ceremony—braces and return statements, for example—can make a big difference. Although the features here may not sound impressive, I’ve been surprised at their impact in real code. We’ll start off looking at properties and move on to methods, indexers, and operators.
C# has had properties from the first version. Although their core functionality hasn’t changed over time, they’ve gradually become simpler to express in source code and more versatile. Properties allow you to differentiate between how state access and manipulation are exposed in the API and how that state is implemented.