Just for the fun of it, I ran this:
int cap = 100000; Stopwatch sw1 = new Stopwatch(); sw1.Start(); int[] ix = new int[cap]; for (int x = 0; x < cap; x++) { ix[x] = 1; } sw1.Stop(); Stopwatch sw2 = new Stopwatch(); sw2.Start(); List<int> iy = new List<int>(cap); for (int y = 0; y < cap; y++) { iy.Add(y); } sw2.Stop(); Console.WriteLine(cap.ToString() + " int[]=" + sw1.ElapsedTicks.ToString()); Console.WriteLine(cap.ToString() + " List<int>=" + sw2.ElapsedTicks.ToString()); Console.ReadKey();
And got this:
100000 int[]=1796542 100000 List=2517922
I tried it in elapsed milliseconds and got 0 and 1 respectively. Clearly the int[] is way faster, but unless you're talking huge arrays, I'd say it is just nominal.
List<int>because you use automatic resizing, then use it. If you just need a static size array, useint[]. Ref. answer by 280Z28 that you accepted.