C# / .NET equivalent for Java Collections.emptyList()?

后端 未结 8 2104
孤街浪徒
孤街浪徒 2020-12-29 02:11

What\'s the standard way to get a typed, readonly empty list in C#, or is there one?

ETA: For those asking \"why?\": I have a virtual method that re

8条回答
  •  孤独总比滥情好
    2020-12-29 02:52

    IList list = new List().AsReadOnly();
    

    Or, if you want an IEnumerable<>:

    IEnumerable sequence = Enumerable.Empty();
    

提交回复
热议问题