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

Allan Blain
Allan Blain
2,418 Points

I need help with creating the multidimensional array that takes a MaxFactor argument.

It seems I am not setting entering the correct arguments in the square brackets for the array.

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

            for (int x = 0; x <= maxFactor; x++)
            {
                arr[x] = new int[x];

                for (int y = 0; y <= maxFactor; y++)
                {
                    arr[x, y] = x * y;
                }
            }

            return arr;
        }
    }
}

1 Answer

Steven Parker
Steven Parker
229,732 Points

:point_right: It looks like you haven't been consistent with the dimensions.

You correctly declare "arr" as a 2-dimensional array, but on the same line you assign it to a scalar (one-dimension) array. You also treat is as a scalar array inside the first loop (that line is unneeded and can be removed).

Also remember the array size must be one larger the than largest index value (maxFactor).