C# C# Collections Arrays Jagged Arrays

Yiu Ming Lai
Yiu Ming Lai
5,861 Points

Anyone know why i am getting "Object reference not set to an instance of an object"?

Anyone know why i am getting "Object reference not set to an instance of an object"?

Math.cs
namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {
        public static int[][] BuildMultiplicationTable(int maxFactor)
        {
           int [][] arr = new int [maxFactor][];
           for (int row = 0; row <= maxFactor; row++)
            {
                for (int col = 0; col <= maxFactor; col++)
                {
                     arr[row][col] = row*col;

                }

             }

            return arr;
        }
    }


}

1 Answer

D O
D O
7,353 Points

You need to initialize your column arrays first before you start assigning values. Someone had the same question here: https://teamtreehouse.com/community/c-collections-challenge-task-jagged-arrays