For a multidimensional array.
if you are not simulating this with a one dimensional array which is more efficient.
Then
// Declaration.
private Texture2D testTexture;
Texture2D[,] TextureArray2d;
Rectangle[,] RectangleArray2d;
protected override void LoadContent()
{
// ... load textures ..
// Instantiation, creation of a 2d array
TextureArray2d = new Texture2D[8, 8];
RectangleArray2d = new Rectangle[8, 8];
// Getting one of a arbitrary 2d dimensions length.
// In this case dimension x y is row column.
int xlength = TextureArray2d.GetLength(0);
int ylength = TextureArray2d.GetLength(1);
// Programatically looping and assigning
int tileSizeX = 32;
int tileSizeY = 32;
for (int x = 0; x < xlength; x++)
{
for (int y = 0; y < ylength; y++)
{
// This is nearly always assigned thru a loop
RectangleArray2d[x, y] = new Rectangle(x * tileSizeX, y * tileSizeY, tileSizeX, tileSizeY);
// This would usually be done in some other way.
TextureArray2d[x, y] = testTexture;
}
}
// Manual assignment of the tile textures.
Texture2D t = testTexture;
TextureArray2d = new Texture2D[,]
{
{t, t, t, t, t, t, t, t},
{t, t, t, t, t, t, t, t},
{t, t, t, t, t, t, t, t},
{t, t, t, t, t, t, t, t},
{t, t, t, t, t, t, t, t},
{t, t, t, t, t, t, t, t},
{t, t, t, t, t, t, t, t},
{t, t, t, t, t, t, t, t}
};
}
// ...
// Drawing.
spriteBatch.Begin();
for (int x = 0; x < xlength; x++)
{
for (int y = 0; y < ylength; y++)
{
Texture2D t = TextureArray2d[x, y];
Rectangle r = RectangleArray2d[x, y];
spriteBatch.Draw(t, r, Color.White);
}
}
SpriteBatch.End();