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

后端 未结 15 1731
盖世英雄少女心
盖世英雄少女心 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:42

    You are correct an array is great for look ups. However modifications to the size of the array are costly.

    You should use a container that supports incremental size adjustments in the scenario where you're modifying the size of the array. You could use an ArrayList which allows you to set the initial size, and you could continually check the size versus the capacity and then increment the capacity by a large chunk to limit the number of resizes.

    Or you could just use a linked list. Then however look ups are slow...

提交回复
热议问题