0

fresh fish here, apologize in advance... I am trying to compare an array to a matrix, each row at a time. (like a check for winning the lottery). I am doing this with three FOR loops and one IF inside of them. I keep getting 'System.IndexOutOfRangeException'. This is the code (without the Curly Braces):

for (int i = 0; i < table.Length; i++)           
                int count = 0;
                for (int j = 0; j < table.Length; j++)                                    
                    for (int k = 0; k < winner.Length; k++)                   
                        if (winner[k] == table[i, j])                   
                            count += 1;

If someone could help I would be so happy :)

  • possible duplicate of [What is IndexOutOfRangeException and how do I fix it?](http://stackoverflow.com/questions/20940979/what-is-indexoutofrangeexception-and-how-do-i-fix-it) – Sarah Elan Apr 20 '15 at 17:17
  • Perhaps, `table[i, j]` should really be `table[i][j]`? Otherwise, it's equivalent to `table[j]`, as `i` has no side-effects... But then again, we can't see the declarations/definitions of your variables, so it's not entirely clear what you're attempting. A language tag would be useful, too - it sorta looks like C, but ... – twalberg Apr 20 '15 at 18:07

0 Answers0