1

I came across this in our code-base today, and it took me awhile to see what the effect of it was, but what in the world does this actually mean??

public virtual SomeClass InstanceVariable => new SomeClass("arg1", "arg2");

I played around with this in Visual Studio's C# interactive terminal and discovered that it appears to be equivalent to:

public virtual SomeClass InstanceVariable { get { new SomeClass("arg1", "arg2"); } }

However, I couldn't find any documentation on this being any form of 'syntactic sugar' for a read-only property.

Someone want to shed some light on the scenario?

1 Answers1

3

It is from new C# 6.0. You can instantiate your class by default. Check "Expression Bodied Functions and Properties" of https://msdn.microsoft.com/en-us/magazine/dn802602.aspx article

Nigrimmist
  • 10,289
  • 4
  • 52
  • 53