It's pointless calling ReadLines
if you are going to call ToArray
. It probably even performs worse than ReadAllLines
. The point of ReadLines
is that it reads one line at a time and exposes that line for processing, so you never have to hold the entire file contents in memory at the same time and you may be able to halt processing without reading the entire file. Imagine searching a file of a million lines for some text that is in the first line. ReadLines
would enable you to read that first line and then stop, while ReadAllLines
would make you wait until all lines had been read into memory and then you'd only use the first one.
For small files, it doesn't really make much difference but it is more correct to use ReadLines
if you are using the data sequentially and only once. For big files, it can make a significant difference so you should definitely use ReadLines
unless you specifically need all the data at the same time, e.g. for random and/or multiple access.