C# C# Collections Arrays Jagged Arrays

Radu - Adrian Buha
PRO
Radu - Adrian Buha
Pro Student 4,504 Points

My code doesn't seem to compile. What am I missing?

So, I'm at the first challenge from C# Collection, and the my code doesn't seem to compile. Can anyone explain why? Many thanks in advance!

Math.cs
namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {
        public static int[][] BuildMultiplicationTable(int maxFactor)
        {
           int result;
            Cell[][] table = new Cell[maxFactor][];
            for(int rowIndex = 0; rowIndex < maxFactor; rowIndex++){
                for(int colIndex = 0; colIndex < maxFactor; colIndex++ ){

                    result = rowIndex*colIndex;
                    table[rowIndex][colIndex] = result;
                    return table[rowIndex][colIndex];
                }
            }
        }
    }
    class Cell{
        public int Contents{ get; set;}
    }
}

1 Answer

Steven Parker
Steven Parker
172,335 Points

Well you have some type mismatches involving the Cell class, but you don't really need that. Try making the table be int[][] instead, which is the declared return type. And here's a few other hints:

  • the dimensions need to go up to and including "maxFactor"
  • remember to initialize the individual rows
  • don't return until the loops finish building the table
  • return the whole table instead of one item from it