C# C# Collections Arrays Multidimensional Arrays

Mohammed Abdalla
Mohammed Abdalla
7,448 Points

i think that i have a problem with my index, but i am not able to discover my mistake

2 Dim Array

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


            int[,] towDimArray = new int[maxFactor,maxFactor];
            for(int x =0 ; x < towDimArray.GetLength(0);x++)
            {
                for(int y =0 ; y < towDimArray.GetLength(1);y++)
                {
                    towDimArray[x,y] = x*y ;
                }
            }
            return  towDimArray;

        }
    }
}

2 Answers

Steven Parker
Steven Parker
172,140 Points

:point_right: Your array is a bit too small.

Since indexes begin at 0, but you want your table to go up to and including the value of maxFactor, your dimensions need to be one larger than maxFactor.

Otherwise, good job! :+1: