我有一個C#新手問題。以下兩點也考慮了良好的做法? ...並列出比陣列更慢或更快?使用列表數組 - 最佳實踐
//Method 1
int[] i_array = { 2, 0, 110, 53455, 2223 };
if (someBolean)
{
Array.Resize(ref i_array, i_array.Length + 1);
i_array[i_array.Length - 1] = someIntValue;
}
//Method 2
var i_list = new List<int>();
i_list.AddRange(new int[] { 2, 0, 110, 53455, 2223 });
if (someBolean)
i_list.Add(someIntValue);
如果你不斷調整數組的大小,不妨在方法2中使用列表。 – 2010-12-02 16:40:23
我知道這很難做到,但是在學習曲線上的這個階段,不要擔心性能,直到性能成爲問題。看到這個問題http://stackoverflow.com/questions/211414/is-premature-optimization-really-the-root-of-all-evil – 2010-12-02 16:58:04