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

前端 未结 15 2171
礼貌的吻别
礼貌的吻别 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:01

    Initializing the contents of a list like that isn't really what lists are for. Lists are designed to hold objects. If you want to map particular numbers to particular objects, consider using a key-value pair structure like a hash table or dictionary instead of a list.

提交回复
热议问题