In C# 6 Microsoft has introduced Expression-bodied Method and properties. Here I am go to explain only about Expression-bodied Properties if you are interested to know about Expression-bodied method then check here .It’s inspired by lambda expression.
In C# 5
- get { return string.Format("{0} {1} {2} {3}", UserId, UserName, EmailId, ContactNumber); }
- class User
- {
- public int UserId { get; set; }
- public string UserName { get; set; }
- public string EmailId { get; set; }
- public string ContactNumber { get; set; }
- public string UserDetails
- {
- get { return string.Format("{0} {1} {2} {3}", UserId, UserName, EmailId, ContactNumber); }
- }
- }
In C# 6
- public string UserDetails => $"{UserId} {UserName} {EmailId} {ContactNumber}";
- class User
- {
- public int UserId { get; set;}
- public string UserName { get; set; }
- public string EmailId { get; set; }
- public string ContactNumber { get; set; }
- public string UserDetails => $"{UserId} {UserName} {EmailId} {ContactNumber}";
- }

Zeeshan AzimPosted Mar 20, 2017, 11:10 PM
Good. Thanks for sharing