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.
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.
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.