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

后端 未结 8 2111
孤街浪徒
孤街浪徒 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:57

    Construct an instance of System.Collections.ObjectModel.ReadOnlyCollection from your list.

    List items = new List();
    ReadOnlyCollection readOnlyItems = new ReadOnlyCollection(items);
    

提交回复
热议问题