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

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

    Starting with .net 4.6 you can also use:

    IList emptyList = Array.Empty();
    

    This does only create a new instance once for every different type you specify as T.

提交回复
热议问题