C# C# Collections Arrays Multidimensional Arrays

Dan Whiting
Dan Whiting
12,660 Points

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

Dan Whiting
Dan Whiting
12,660 Points

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;
        }
    }
}
Ole Vølund Skov Mortensen
Ole Vølund Skov Mortensen
Pro Student 20,611 Points

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