Luke Warren Dev
Software Development Tips and Stories When I feel Like It

C# 6: Shorten all the things with expression-bodies

Let's see how you can use expression-bodies

,
C# 6: Shorten all the things with expression-bodies

Let's see how you can use expression-bodies to make your code a lot shorter and more readable.

If you are still writing code like this:

public string FullName 
{ 
    get 
    { 
        return String.Format("{0} {1}", First, Last); 
    } 
}

You really should read my string interpolation post , and write it like this:

public string FullName 
    {
         get 
         { 
               return $"{First} {Last}"; 
         }
     }

The thing is, it gets even better with expression-bodies:

public string FullName => $"{First} {Last}";

That is all.


comments powered by Disqus