-1

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,232
  • 4
  • 22
  • 32

1 Answers1

4

Use the Enumerable.Empty<type> function.

IEnumerable<int> Ids => Enumerable.Empty<int>();
3per
  • 333
  • 6
  • 25
Zoka
  • 2,232
  • 4
  • 22
  • 32