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
172,090 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).