Hi,
A simple basic question:
I have an application in which I read ocasunally lines from a text file.
I currently use StreamReader and LoadLine() in a loop to call.
My problem is that I do not want to keep the file open all the time, and therefroe I wish to load the file bulk to memory and close the file, and then read lines from memory, (like the Readline()).
Please advise.
Sam
Load text file to memory, read by lines
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Sam HobbsRank #108 · 20.5K reputationPosted Oct 21, 2010, 12:31 PM EDT
Sam159 reputationPosted Oct 21, 2010, 1:34 PM EDT
Only comment is that the syntax is somewhat different, but the idea helped me out.
//The code that works looks as follows:
StreamReader file = new StreamReader(fileName);
string mystring = file.ReadToEnd();
file.Close();
char[] delimiter = new char[] { '\r', '\n' };
string[] line = mystring.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < line.Length; i++)
{
Console.WriteLine(line[i]);
}
Sam