C# Simple question about arrays
C# code: int[ ] a = new int[10]; for (int k = 1; k <= 10; k++) { a[k] = k*2; } for (int k = 0; k < 10; k++) { Console.WriteLine(a[k]); } Why do I still get 0 as the output of the first value? From the first for loop I declared k's value as 1 and should be rendering 2...20 instead it shows 0...18 It gives an error of "out of bounds". if I change the first loops condition to <= 9. it still gives me 0 as the initial value and stops at 18 update: so it seems 0 could be a default value given to the "0" position. I would imagine that it would be the last/10th position that would be set with the value of 0. But theres still the question, why doesnt k <= 10 work?