creating 2d array of objects

I’m playing with arrays so i can get a little more comfortable with them.
as a test i wrote this bit of code it is supposed to create an array of 16x 16 cubes
But it seems to create more and more over the top of each other like I’m iterating the whole process but I’m not sure why?

sing UnityEngine;
using System.Collections;

public class ObjArray : MonoBehaviour {
	
	public int ArraySize = 16;
	public GameObject cube;

	// Use this for initialization
	void Start () {
		cube = GameObject.Find("PREFAB_cube");
	}
	
	// Update is called once per frame
	void Update () {
		
		GameObject [ , ] cubes = new GameObject [ ArraySize , ArraySize ];

		for(int i = 0; i < ArraySize; i++)
		{
			for(int j = 0; j < ArraySize; j++)
			{
				cubes[i,j] = (GameObject) Instantiate (cube ,
				                                       new Vector3(i,j,0) ,
				                                       Quaternion.identity);
			}
		}

	}
}

You are creating your cubes in Update(). Update() gets called once per frame. So if your app was running at 30 fps, you would be creating nearly 8000 cubes per second. Of course as the number of cubes in the game goes up, your frame rate will drop.

Move your code for cube creating into Start(), and you will only get a single set of cubes.