Unity Object Array C#

Hi there, Im trying to populate an object array in unity using C#, i declare the array like this:

Card[][] aCardGrid;

When I try to assign the card object to the array

aCardGrid*[j] = new Card();*
*```*
*<p>I get this error:</p>*
*<p>NullReferenceException: Object reference not set to an instance of an object*
*GameScript.Start () (at Assets/Scripts/GameScript.cs:29)</p>*
*<p>I tested the creation of the object and it's working fine, just get this error when i try to put it inside the array...</p>*
*<p>Anyone?</p>*

Do you ever instantiate the array? That part of the code is missing

If not:

aCardGrid = new Card[xSize][ySize];

Edit just for sanity's sake:

You can also use a multidimensional array instead:

Card[,] aCardGrid;
aCardGrid = new Card[xSize, ySize];

You won't need to populate the jagged array yourself with inner arrays, and it's guaranteed to be a fixed size in each direction

This code segment gives me the error Invalid rank specifier: expected ',' or ']' \Program.cs ConsoleApplication4

Adding this answer to support the reminder to fill the 3D array with nested for

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            Foo f = new Foo();

            Foo[][] myArray = new Foo[2][3];
        }
    }

    class Foo
    {
        public int x;

        public Foo()
        {
            x = 1;
        }
    }

}