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 Multidimensional Arrays

Fredrik Rönnehag
Fredrik Rönnehag
2,342 Points

Multidimensional Array

I passed the exercise, but I'm not quite sure I did it the correct way. For an example, right now I don't use the int maxFactor anywhere, but I still passed.

I would rather learn the right way and understand the excercise correctly!

namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {
        public static int[,] BuildMultiplicationTable(int maxFactor)
        {
         int[,] array = new int[6, 6];

            for (int row = 0; row < array.GetLength(0); row++)
            {
                for (int col = 0; col < array.GetLength(1); col++)
                {
                    array[row, col] = row * col;
                }
            }
            return array;
        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,269 Points

I'm guessing that while working on this, you got the error message "Bummer: The table should contain 6 rows and 6 columns". That was a bit too much information. It probably should have said "The table does not contain the right number of rows and columns".

A more correct solution would not contain the number "6" but would determine the sizes based on "maxFactor".

Fredrik Rönnehag
Fredrik Rönnehag
2,342 Points

Ah, so it should be int[,] array = new int[maxFactor, maxFactor]; ?

Yea, got that message so I changed the array to 6,6 and got a bit confused since it wasn't in the instructions.

Steven Parker
Steven Parker
231,269 Points

Close, but the dimensions need to be one more than the maximum factor (since index values start at 0).