0

C#, Arrays & loops. first page

Dear guys, can someone help me with a question? I have a problem in understanding the second loop. My understanding is as follows: The first loop initialized the content of the array a with its variable k [0,2,4,6,8,10,12,14,16,18]. The second loop doesn`t create even numbers, because a[k] = k*2 is missing. Why does the "try it yourself" code: int[ ] a = new int[10]; for (int k = 0; k < 10; k++) { a[k] = k*2; } for (int k = 0; k < 10; k++) { Console.WriteLine(a[k]); } Outputs the data of the first loop, and not the data of the second loop? I thought the second loop would create k [0,1,2,3,4,5,6,7,8,9]. Best regards

15th Sep 2018, 11:20 AM
Thorsten Franz Brune
Thorsten Franz Brune - avatar
2 Answers
0
The 2nd loop doesn't create anything, it only prints the areay
15th Sep 2018, 11:22 AM
Alexandru Turculet
Alexandru Turculet - avatar
0
AAH understood.
15th Sep 2018, 11:33 AM
Thorsten Franz Brune
Thorsten Franz Brune - avatar