Mahek
  • Blog
  • About
  • Contact
  • Random Clicks

Fragrance
​of Programming

C# 6.0 New Features - Expression Bodied Function

4/16/2015

Comments

 
Today we are going to explore yet another new feature of C# 6.0 which will be coming in this release. This is my fifth post in the series of C# 6.0 New Features. Don't forget to read my previous post in this Series :

  • C# 6.0 New Features - Null Conditional Operators
  • C# 6.0 New Features - Default Values to Auto Properties
  • C# 6 New Features - nameof Expressions
  • C# 6.0 New Features - String Interpolation

In C# 6.0 Microsoft has included yet another great feature called as "Expression-bodied Function" and to explore and experience more about that you need to download Visual Studio 2015 and .NET Framework 4.6.

Expression-bodied function allows properties, methods, operators and other functions to have bodies just like Lambda expressions instead of blocks of statements, thus reducing lines of codes and becomes more readability. But from my experience there are many Developers who still prefers writing code in the old fashion because according to them it’s clearer and less confusing. Anyways it all comes to the personal choice. 

So now in C# 6.0 instead of writing the whole property body using getters and setters, Developer can now just use the lambda operator (=>) to return values. Below is the example.
Picture
Picture
And very similar to property, you can use Expression Bodied function to methods which returns value to the caller. Below is the example.
Picture
Developer can use this feature even for methods returning void as well as Task returning async. Syntax remains the same as above example.
How exactly it will be beneficial is still a question but it will definitely reduce the line of codes, which I am sure some would prefer and some would not.
Comments
comments powered by Disqus

    RSS Feed

    Categories

    All
    Azure
    C#
    Cloud
    CodeProject
    CSharp
    DotNet Core
    Jetbrains
    .NET
    Rider
    SQL
    Tech News
    Ubuntu
    Visual Studio 2015
    Visual Studio 2019
    Windows
    Windows 10

    Archives

    February 2019
    January 2019
    December 2018
    May 2018
    December 2017
    November 2017
    October 2017
    September 2017
    July 2017
    May 2017
    April 2017
    May 2015
    April 2015
    March 2015

    View my profile on LinkedIn

Location

Contact Us

    Subscribe Today!

Submit
  • Blog
  • About
  • Contact
  • Random Clicks