Javatpoint Logo
Javatpoint Logo

C# Expression-bodied members

C# expression bodied members allows us to define members (property or method) definition in a single expression.

This expression is very concise and readable in nature.

We can use expression body definition with the following.

  • Method
  • Property Get

C# Expression-bodied members syntax

C# Expression-bodied method

It consists of a single expression. If method has a return type, expression must return similar type. Let's see an example.

C# Expression-Bodied Method Example


Peter John

C# Expression bodied Property Get

We can use expression body to implement get property. A single expression can be used to set a value for the property.

We should not use return statement in this property.

Let's see an example, that implements expression body in get property.

C# Expression-Bodied Get Property Example



Next TopicC# Null Propagator

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA