I have a file which contains a certain number of fixed length rows having some numbers. I need to read each row in order to get that number and process them and write to a file. Since I need to read each row, as the number of rows increases it becomes time consuming.
Is there an efficient way of reading each row of the file? I'm using C#.
File.ReadLines
(.NET 4.0+) is probably the most memory efficient way to do this.
It returns an IEnumerable<string>
meaning that lines will get read lazily in a streaming fashion.
Previous versions do not have the streaming option available in this manner, but using StreamReader
to read line by line would achieve the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With