Loop Through array of Array

  • Thread starter Thread starter old_School
  • Start date Start date
O

old_School

Guest
Not sure why I'm getting error:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Word_Search
{
class Program
{
static void Main(string[] args)
{
WordFinder WordFinder = new WordFinder();

//Build Matrix

//Across
WordFinder.matrix[0, 0] = WordFinder.GenerateChar();
WordFinder.matrix[0,1] = WordFinder.GenerateChar();
WordFinder.matrix[0,2] = WordFinder.GenerateChar();
WordFinder.matrix[0,3] = WordFinder.GenerateChar();
WordFinder.matrix[0,4] = WordFinder.GenerateChar();
WordFinder.matrix[0,5] = WordFinder.GenerateChar();
WordFinder.matrix[0,6] = WordFinder.GenerateChar();
WordFinder.matrix[0,7] = WordFinder.GenerateChar();
WordFinder.matrix[0,8] = WordFinder.GenerateChar();
WordFinder.matrix[0,9] = WordFinder.GenerateChar();
WordFinder.matrix[0,10] = WordFinder.GenerateChar();
WordFinder.matrix[0,11] = WordFinder.GenerateChar();
WordFinder.matrix[0,12] = WordFinder.GenerateChar();
WordFinder.matrix[0,13] = WordFinder.GenerateChar();
WordFinder.matrix[0,14] = WordFinder.GenerateChar();
WordFinder.matrix[0,15] = WordFinder.GenerateChar();
WordFinder.matrix[0,16] = WordFinder.GenerateChar();
WordFinder.matrix[0,17] = WordFinder.GenerateChar();
WordFinder.matrix[0,18] = WordFinder.GenerateChar();
WordFinder.matrix[0,19] = WordFinder.GenerateChar();
WordFinder.matrix[0,20] = WordFinder.GenerateChar();
WordFinder.matrix[0,21] = WordFinder.GenerateChar();
WordFinder.matrix[0,22] = WordFinder.GenerateChar();
WordFinder.matrix[0,23] = WordFinder.GenerateChar();
WordFinder.matrix[0,24] = WordFinder.GenerateChar();
WordFinder.matrix[0,25] = WordFinder.GenerateChar();

//Display Matrix
foreach (string s in WordFinder.matrix)
{
Console.WriteLine(s);
}

//Wait
Console.ReadLine();
}
}
}



Gives me a error on my Foreach statement:

System.IndexOutOfRangeException
HResult=0x80131508
Message=Index was outside the bounds of the array.
Source=Word_Search
StackTrace:
at Word_Search.Program.Main(String[] args) in C:\Users\Mholmes\source\repos\Word_Search\Word_Search\Program.cs:line 45

Continue reading...
 
Back
Top