Multi array class definition C#

Hi, I am asking quite a basic question. I have the javascript version running but not for c#

public class XXX : MonoBehaviour {

    int cols =4, rows = 4;
    Card[][] aCards;

void Start () {
	aCards = new Card[rows][];

	for(int i = 0; i < rows; i++){
		for(int j = 0; j < cols; j++){
			aGrid*[j] = new Card();  //<-------- error points to here*
  •   	}*
    
  •   }* 
    
  • }*
    }
    public class Card{


    }
    When running the above code, I encounter the following error message. "NullReferenceException: Object reference not set to an instance of an object
    (wrapper stelemref) object:stelemref (object,intptr,object)"
    I can use an array list but i’m trying to understand whats wrong with this basic code.
    My purpose is simply to assign a new class for every object in the 2D array. Any advice? Thank you.

You are declaring a jagged array here, so while you created the rows, you have not created the array that “hangs off” each of the rows. Here is one link for more information on Jagged arrays:

http://msdn.microsoft.com/en-us/library/2s05feca(v=vs.80).aspx

For a standard 2D array you can do something like this at the top of the class:

int cols =4, rows = 4;
Card[,] aCards = new Card[rows,cols];