Expression Bodied functions is a relatively new concept brought to use in C# 6.0 to facilitate the creation of properties that included too much ceremony.
C# 7.0 remove even more ceremony from many more concepts.
C# 6.0
Previously, C# 6.0 introduced the concept of Expression bodies functions.
Here are a few examples.
1 | // get only expression bodied property |
C# 7.0
With the new release of C# 7.0, the concept has been added to:
- constructors
- destructors
- getters
- setters
Here are a few examples.
1 | class TestClass |
The difference
The main difference in your code will be the amount of line of codes that will be used for useless curly braces or plumbing code.
Yet again, this new version of C# offer you more ways to keep your code concise and easier to read.
Are you going to use it?
I know that not everyone will necessarily use all of these new form of expression body. But I’m interested in your opinion.
So please leave me a comment and let me know if it’s something that will simplify your life or, at least, your code.