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

后端 未结 8 2092
孤街浪徒
孤街浪徒 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 03:11

    If you want a list whose contents can't be modified, you can do:

    ReadOnlyCollection foos = new List().AsReadOnly();
    

提交回复
热议问题