Expression bodied members in constructors and get-set properties in C# 7.0

Expression bodied members were introduced in C# 6 for methods and properties. This feature has been extended to constructors and getters/setters in C# 7.0.

Here’s an example:

public class Dog
{
	private string name;

	public Dog(String name) => this.name = name;	

	public string NameFormatted
	{
		get => name.ToUpper();
		set => name = value.ToUpper();
	}

	public string Name
	{
		get => name;
	}
}

View all various C# language feature related posts here.

Advertisement

About Andras Nemes
I'm a .NET/Java developer living and working in Stockholm, Sweden.

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 )

Connecting to %s

Elliot Balynn's Blog

A directory of wonderful thoughts

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

WEB APPLICATION DEVELOPMENT TUTORIALS WITH OPEN-SOURCE PROJECTS

Once Upon a Camayoc

Bite-size insight on Cyber Security for the not too technical.

%d bloggers like this: