2
I am trying to read a very large file row by row and add in a list, but when it arrives at a certain point I get an error: System.OutOfMemoryException
Is there any way to read this whole file in a single time?
while ((line = trPlaces.ReadLine()) != null)
{
var htmlLine = line.Split('\t');
try
{
var newPlace = new Place
{
Id = htmlLine[0],
Name = htmlLine[2],
IsoCountry = htmlLine[8],
Latitude = htmlLine[4],
Longitude = htmlLine[5],
Admin1 = htmlLine[10].Length == 1 ? "0" + htmlLine[10] : htmlLine[10],
Admin2 = htmlLine[11],
PlaceType = htmlLine[7],
AlternativeNames = htmlLine[3].Split(',')
};
if(listPlaces1.Count< 4000000)
{
listPlaces1.Add(newPlace);
} else
{
listPlaces2.Add(newPlace);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}