This blog post is part of C# 6.0 Features Series.There are lots of great features added to C# 6.0 and Expression bodied members are one of them. It’s provide great syntax sugar which will help you make your code more beautiful and readable. In earlier versions of C# type definitions were always been tedious and we need to provide a curly braces and return type even if that function contains one single line. Expression bodied function will help you in such scenarios.
Let’s take a example to understand it. Following is a code to understand it.
using System; namespace ExpressionBodiedMemebers { class Program { static void Main(string[] args) { Person person = new Person { FirstName = "Jalpesh", LastName = "Vadgama" }; Console.WriteLine(person.GetFullName()); } } public class Person { public string FirstName { get; set; } public string LastName { get; set; } public string GetFullName() { return string.Format("{FirstName} {LastName}"); } } }