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

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

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.

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