How and when to abandon the use of arrays in C#?

后端 未结 15 1724
盖世英雄少女心
盖世英雄少女心 2020-12-13 02:58

I\'ve always been told that adding an element to an array happens like this:

An empty copy of the array+1element is created and then the data from t

15条回答
  •  盖世英雄少女心
    2020-12-13 03:44

    In general, I prefer to avoid array usage. Just use List. It uses a dynamically-sized array internally, and is fast enough for most usage. If you're using multi-dimentional arrays, use List>> if you have to. It's not that much worse in terms of memory, and is much simpler to add items to.

    If you're in the 0.1% of usage that requires extreme speed, make sure it's your list accesses that are really the problem before you try to optimize it.

提交回复
热议问题