Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Collections Arrays Jagged Arrays

Radu - Adrian Buha
PLUS
Radu - Adrian Buha
Courses Plus Student 5,535 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
229,783 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