C# dynamic char[,] from file?

I am still a bit new to c#/unity, and I would like to dynamically create a 2d char array. So I have an object(levelLoader) with a mostly working script below.

This is functional, but is not dynamic, and a massive kludge. Is can someone help me out?

The text file is nothing by simply chars with a end of line char '/n' ... thoughts?

void Start()
{
    //load the mapfile into the data line
    char[] dataLine = mapFile.text.ToCharArray();
    int row = 0;
    int col = 0;
    char[,] mapMatrix = new char[2000, 2000];
    int x = 0;
    int y = dataLine.Length;
    while (x < y)
    {
        if (dataLine[x] == '
')
        {
            row++;
            x++;
            col = 0;
        }
        //Debug.Log(Spot0 + " " + Line0);
        else
        {
            mapMatrix[row, col] = dataLine[x];
            x++;
            col++;
        }

    }

}

I'd probably store the size of the mapMatrix you required inside the mapFile.txt up the top as some form of meta data. You could then just grab the dimensions first thing after opening the file and create the array.

Otherwise you'll probably need to use some form of container

Personally never used a multidimensional array for anything but small data that requires very quick processing. I find the functionality and cleanness of a container much more convenient. You do lose the ability to use multiple dimensions but finding the required index from a x/y value is easy as y * width + x;

Well, in your case I would suggest to use a string array (or maybe a List )instead ot your 2-dimentional char array:

string[] mapMatrix = null;

void Start()
{
    //load the mapfile
    mapMatrix = mapFile.text.Split('
');

    // access via mapMatrix[row][col]
}

If you need more information in one cell I would use a `List<List>`