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

前端 未结 15 2203
礼貌的吻别
礼貌的吻别 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条回答
  •  旧时难觅i
    2020-11-28 06:43

    You seem to be emphasizing the need for a positional association with your data, so wouldn't an associative array be more fitting?

    Dictionary foo = new Dictionary();
    foo[2] = "string";
    

提交回复
热议问题