Tech Off Post

Single Post Permalink

View Thread: Index was outside the bounds of the array.
  • User profile image

    gwarburton wrote:

    I have a foreach loop iterating through a 2-dimensional array.  When I locally declare the array variable the loop operates correctly, however, when it is publicly declared it crashes with the "IndexOutOfRangeException" error.

    This could be caused because you are using multiple threads or something along those lines.  Remember also when you declare your array, it's not enough to just declare the size, you have to instantiate the members of the array. 

    A code sample would be helpful. 

    Did you declare your array like this [,] or this [][]?