-2
protected override IEnumerable<string> Attributes => new []
{
  IntercationAttributes.State
};

Can somebody explain me what is happening here. Why we have new[] with lambda expression. I have seen it for the first time.

Rahul Sharma
  • 453
  • 3
  • 10

1 Answers1

2

This is not an anonymous method (a.k.a. lambda expression) but instead a way to write computed properties in a more concise manner. It's exactly equivalent to

protected override IEnumerable<string> Attributes {
  get { return new [] { IntercationAttributes.State };
}

As you can see, a read-only property of the form

<property> { get { return <expression>; } }

can be written as

<property> => <expression>;

in C# 6, reducing the syntax around the declaration a bit.

Joey
  • 344,408
  • 85
  • 689
  • 683