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
The best way to know how to do this fast is to think about the fastest way to do it without using C/C++.
In assembly there is a CPU level operation that scans memory for a character so in assembly you would do the following
So, in C# you want the compiler to get as close to that as possible.