0

Why is my code not working?

I'm new to coding and I'm learning C# as my first language. Can you tell me what is wrong with my code, I'm using visual studio to create my codes and then I put them into Sololearn's playground. I'm using 2022 Visual Studio. Here is my code. int[ ] b = {11, 12, 13, 14, 15, 16, 17, 18,}; Console.WriteLine(b[11]); Console.WriteLine(b[12]);

20th Mar 2022, 12:24 AM
jolly elmroot
jolly elmroot - avatar
5 odpowiedzi
+ 3
jolly elmroot You are accessing 11th and 12th index value in array b which doesn't exist because array b has only 8 elements. So you can access till 7th index as index start from 0
20th Mar 2022, 1:29 AM
A͢J
A͢J - avatar
+ 2
indexing starts with 0 and your array only has 8 integers. So try printing with the index values 0 - 7
20th Mar 2022, 12:29 AM
Slick
Slick - avatar
+ 2
Thank you guys I’ll try this!
20th Mar 2022, 12:37 AM
jolly elmroot
jolly elmroot - avatar
+ 2
Thank you guys, I get it now! I realized that I put the elements in the Console.WriteLine… that was my mistake. I’ll post it in playground!
20th Mar 2022, 12:44 AM
jolly elmroot
jolly elmroot - avatar