Sorry to post an XNA question here but I can't find the answer to this anywhere including XNA and C# forums.
Does anybody know how to read a text file into a 2D array in C#. I have this:
int[,] map; FileStream fileStream = new FileStream(@"Map.txt", FileMode.Open); map = new int[5,5]; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { map[i,j] = // what goes here? } }
Any direction is much appreciated.
Thanks!
What are you trying to read from your file? - if it is simply an array of chars:
If it is an array of integers, then you will need to split it by some separator per line, and parse the individual integers.
Show us an example file.
Actually yeah, an array of chars was fine. I was focusing on reading ints and having a lot of trouble but chars did the job just fine. It was a lot of unnecessary frustration.
Thanks guys!