c# - Using list arrays - Best practices -


i have c# newbie question. consider practice out of 2 below too? ...and list slower or faster array?

        //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); 

the later considered best practice variable size collections.

depending on type of collection you're using, framework class internally similar you're doing in first example (except instead of resizing 1 element, increments larger size have buffer space keep adding elements).

in general, though, don't want re-invent wheel. framework provides ton of collection classes variable size. use them instead of writing own.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -