Here's a piece of code coming from a C# project using a 2d array. For a reason I don't understand my program compiles perfectly but during run-time it crashes.
public class Tile_Info
{
public int id;
public Tile_Info(int _id)
{
id = _id;
}
}
class Program
{
public static void Main(string[] args)
{
int width = 20;
int height = 30;
Tile_Info[,] my_tile;
my_tile = new Tile_Info[width, height];
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
my_tile[x, y].id = 0;
}
}
}
}
According to the debugger it's because "Object reference not set to an instance of an object", but I'm pretty sure it's what I'm doing here: my_tile = new Tile_Info[width, height];.
Anyone can tell what's wrong? Thank you for your support!