Bhavya

Code -> Break -> Fix -> Blog

C# 6.0 : Function & Property with Lambda expression (Expression Body)

1 Comment

Another C# 6.0 feature which simplifies the syntax is the use of Lambda expression with Functions.

Developers commonly overrides the ToString() method of the object class.

 public override string ToString()
 {
 return "\{LastName}, \{FirstName}";
 }

But with C# 6.0, this is made simple with the use of Lambda expression with Function (this can be implemented for any Function not restricted to ToString()).

public override string ToString() => "\{LastName}, \{FirstName}";

The same can also be done for Property.

public string FullName => "\{LastName}, \{FirstName}";

You will notice that return string is not in a familiar format for that I suggest you look at my String interpolation blog.

Let me know you thoughts.

~BS

Twitter Logo

Advertisements

One thought on “C# 6.0 : Function & Property with Lambda expression (Expression Body)

  1. Pingback: New Features of C# 6.0 | Bhavya

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s