How to initialize a List to a given size (as opposed to capacity)?

前端 未结 15 2227
礼貌的吻别
礼貌的吻别 2020-11-28 06:41

.NET offers a generic list container whose performance is almost identical (see Performance of Arrays vs. Lists question). However they are quite different in initialization

15条回答
  •  余生分开走
    2020-11-28 07:05

    A notice about IList: MSDN IList Remarks: "IList implementations fall into three categories: read-only, fixed-size, and variable-size. (...). For the generic version of this interface, see System.Collections.Generic.IList."

    IList does NOT inherits from IList (but List does implement both IList and IList), but is always variable-size. Since .NET 4.5, we have also IReadOnlyList but AFAIK, there is no fixed-size generic List which would be what you are looking for.

提交回复
热议问题