0

Imagine you have to implement interface required property:

IEnumerable<int> Ids { get; }

which (implemented) returns empty enumeration. You may write:

public IEnumerable<int> Ids
{
    get { yield break; }
}

But is there a way how to use expression bodied member syntax, so you may have this on single line?

Zoka
  • 2,312
  • 4
  • 23
  • 33

1 Answers1

4

Use the Enumerable.Empty<type> function.

IEnumerable<int> Ids => Enumerable.Empty<int>();
3per
  • 351
  • 9
  • 26
Zoka
  • 2,312
  • 4
  • 23
  • 33