6
Answers

IndexOutOfRangeException while retriving data from array?

Matthew Lugg

Matthew Lugg

11y
1.9k
1

Hi!

In a C# DLL, I have a for loop that retrieves data from an array named numbers. However, when the code to retrieve it runs, I get an IndexOutOfRangeException.

The exception says:

"An unhandled exception of type 'System.IndexOutOfRangeException' occurred in ClassLibrary1.dll

Additional information: Index was outside the bounds of the array."

The code is:


for(int i = 0; i <= numbers.Length - 1; i++)

{

        where.Text += numbers[i].ToString() + " /r/n ";

}


I apologise if it is something obvious - I am a beginner.

Many thanks.


Answers (6)
Next Recommended Forum