I'm using File.ReadLines().ToList()
to read a regular text file into a List<string>
.
The text file has 2 blank lines, like so ('View all characters' enabled in notepad++ for clarity):
Example code:
List<string> lines = null;
try{
lines = File.ReadLines("C:\path\to\file.txt").ToList();
}catch(Exception e){
//code here to handle e
}
Console.WriteLine(lines.Count.ToString());
Prints "1" to console.
My question is, why does my list that is generated by File.ReadLines().ToList()
only have a Count
of 1 when the file has 2 lines? Is a blank line at the end of the file just discarded by default? (it seems so)