I have a text file that has the following in it: (Without quotation marks and “Empty Space”)
- ##############
- # Empty Space#
- # Empty Space#
- # Empty Space#
- # Empty Space#
- ##############
I want to add this whole file row by row into a list:
FileStream FS = new FileStream(@"FilePath",FileMode.Open);
StreamReader SR = new StreamReader(FS);
List<string> MapLine = new List<string>();
foreach (var s in SR.ReadLine())
{
MapLine.Add(s.ToString());
}
foreach (var x in MapLine)
{
Console.Write(x);
}
Here comes my problem: I want to add this into a Two dimensional array. I tried:
string[,] TwoDimentionalArray = new string[100, 100];
for (int i = 0; i < MapLine.Count; i++)
{
for (int j = 0; j < MapLine.Count; j++)
{
TwoDimentionalArray[j, i] = MapLine[j].Split('\n').ToString();
}
}
I am still new to C# so please any help will be appreciated.
You can try with this:
This is going to save each character of the file content into it’s own position in a 2-dimensional array. For that purpose
char[,]might have also been used.