C# C# Collections Arrays Jagged Arrays

Andrew McPheron
Andrew McPheron
14,290 Points

Code looks fine in debugger, but getting 'table should have 6 rows and columns'

I pasted my code into visual studio to use the debugger on it, but I'm seeing 6 rows and 6 columns with correct values when I hover over my sheet variable. I've seen some other answered questions that say to increase the max value by one, but the question currently says to return from 0 to maxValue and even shows the zeros in the example code. What am I missing here?

Math.cs
namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {
        public static int[][] BuildMultiplicationTable(int maxFactor)
        {
            int[][] sheet = new int[maxFactor][];
            for (int x = 0; x < maxFactor; x++)
            {
                int[] values = new int[maxFactor];
                for (int y = 0; y < maxFactor; y++)
                {
                    values[y] = x * y;
                }
                sheet[x] = values;
            }
            return sheet;
        }
    }
}

2 Answers

Andrew McPheron
Andrew McPheron
14,290 Points

I ended up fixing it by adding the following code to the very start of the method:

maxResult++;

Turns out it's just a matter of the input number being one lower than expected. Ah well.

Ryan Pierson
Ryan Pierson
14,365 Points

Thanks! That was what I was wrestling with as well!