Why is throwing an exception ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why is throwing an exception ?

I'm trying to code a solution for project euler(1001st prime) but it's keep throwing a "outside the bounds of an array" exception at me.How can I fix it. https://code.sololearn.com/c9grd03e04Ui/?ref=app

12th Sep 2020, 8:15 AM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
4 Answers
+ 2
There is only 1 element in result[], so IndexOutOfRangeException is thrown.
12th Sep 2020, 8:32 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
Console.WriteLine(result[10]); This is causing your error. The array does not have 11 elements when you try to access it.
12th Sep 2020, 8:31 AM
Tibor Santa
Tibor Santa - avatar
+ 1
How can i fix it
12th Sep 2020, 9:20 AM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
0
How does it have only one element
12th Sep 2020, 9:22 AM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar