While looking around for a while I found quite a few discussions on how to figure out the number of lines in a file.
For example these three:
c# how do I count l
There are numerous ways to read a file. Usually, the fastest way is the simplest:
using (StreamReader sr = File.OpenText(fileName))
{
string s = String.Empty;
while ((s = sr.ReadLine()) != null)
{
//do what you gotta do here
}
}
This page does a great performance comparison between several different techniques including using BufferedReaders, reading into StringBuilder objects, and into an entire array.