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

Mutlidimensional array code challenge

I think i'm having a problem with my initializer? I'm definitely screwing up somewhere here. Any clues?

Math.cs
namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {
        public static int[,] BuildMultiplicationTable(int maxFactor)
        {
            int[,] arr = new [maxfactor, maxfactor + 1];
            for(int i = 0; i < arr.GetLength(0); i++){
                for(int j = 0; j < arr.GetLength(1); j++){
                    arr[i, j] = new int();
                    arr[i, j] = i * j;
                }
            }
            return arr;
        }
    }
}

1 Answer

I figure it out! I forgot to set a type on my array and also add +1 to both lengths.

namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {
        public static int[,] BuildMultiplicationTable(int maxFactor)
        {
            int[,] arr = new int [maxfactor + 1, maxfactor + 1];
            for(int i = 0; i < arr.GetLength(0); i++){
                for(int j = 0; j < arr.GetLength(1); j++){
                    arr[i, j] = new int();
                    arr[i, j] = i * j;
                }
            }
            return arr;
        }
    }
}

Had to Fix your spelling in "maxfactor" to "maxFactor" else this is cool. i need though to study this method to understand how it's logic works