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

Return a multiplication table consisting of an array of arrays. The table should contain all of the products of integers

This challenge question doesn't help me much for what's expected to solve this one. My code gives no compiler errors when I check it but I get the error: Bummer: Object reference...https://teamtreehouse.com/library/c-collections/arrays/jagged-arrays#preview

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

            for(int indexX = 0; indexX <= maxFactor; indexX++)
            {
                for(int indexY = 0; indexY <= maxFactor; indexY++)
                {
                    table[indexX][indexY] = indexX * indexY;
                }
            }

            return table;
        }
    }
}

2 Answers

Steven Parker
Steven Parker
231,198 Points

You're close, but:

  • the outer loop should create the inner array for the column and assign it to the table
  • the arrays need to be sized larger than maxFactor (since the indexes start with 0)

Yeah I finally got it to work thanks. It stumped me for a while, but I just needed to take a break and then got it to work.