I need a two-dimensional array of objects as a field in a class "World". When the class "World" is initialized, I do not yet know the size of the two-dimensional array, since this is set in a GUI after initialization. How do I do this? I have searched for examples where the array is initialized as empty, but how do I then resize the array after initialization? I am probably approaching this situation in the wrong way, but since I need the field in the world object and don't know the size of the array at initialization, I'm stuck. Any advice would be appreciated.
I tried initializing an empty array, but can't find how to resize a multi-dimensional array. I also thought about putting the array in another class, but in such a case that class would need to be initialized as well, so that won't solve this problem. A List is probably not the solution since I'm working with a two-dimensional grid, and I assume a two-dimensional array would be most appropriate for that. Below is the relevant example. Without initializing the squareGrid array in the constructor, I get "Severity Code Description Project File Line Suppression State Warning CS8618 Non-nullable field 'squareGrid' must contain a non-null value when exiting constructor. Consider declaring the field as nullable."
public class World
{
Square[,] squareGrid;
public World(ref DimensionsAndStuff dimstuffIn)
{
// some other stuff going on
}
}