Expression Bodied Functions and Properties in C# 6.0

Posted by Anuraj on Wednesday, December 3, 2014 Reading time :1 minute

.Net ASP.Net Visual Studio

Expression bodied functions are another syntax simplification in C# 6.0. These are functions with no statement body. Instead, you implement them with an expression, similar to Lamda expressions.

class Calculator
    public int Add(int a, int b) => a + b;
    public int Subtract(int a, int b) => a - b;

As with most of the features found in C# 6.0, they’re intended to provide a simplified syntax for cases where the implementation is simple. The return type of the expression should match the return type identified in the function declaration. Void methods, don’t return anything. The expression bodied simplification also available for properties (getter only).

What do you think? I would like to hear your thoughts, suggestions, and questions in the comments section below.

Similar Posts

Did you like this article? Share it with your friends

Facebook Twitter Google+ LinkedIn Reddit StumbleUpon

BMC logoBuy me a coffee

Copyright © 2019 - Anuraj P. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Hosted with ❤ by GitHub