C# 6 Features: Expression Bodied Methods

by Joseph on Feb 4th in .Net, C#

Ok this is going to be a short one. We’ve seen how theĀ Expression Bodied Auto Properties can simplify things a little bit. But, if that is possible, then what about other things with simple bodies? Turns out, Methods are fair game as well.

This is turning in to a fairly popular language change. Again, it’s not a significant change to how C# works, or how you write code, it’s essentially syntactic sugar that makes life just a little bit easier.

It lets us take code like this:

[gist id=”340ccc16e74be9f47674″ file=”Before.cs”]

And turn it into code that looks like this:

[gist id=”340ccc16e74be9f47674″ file=”After.cs”]

It’s not a huge change. I wouldn’t go out and re-write production applications in order to make use of it. But, it will simplify things moving forward, and perhaps make things just a little more readable.

Also, some of the folks in the F# world seem to think this is a move towards a more “functional language” paradigm, and that this is a good thing. We shall see.

Leave a Reply

Powered By Wordpress Designed By Ridgey