This question already has an answer here:
I have huge files in c# (more than 300 MB). I need effiecent way to read the file line by line because once I try to read it it takes more than 30 minutes while the target time is around 3 minutes. I tried File.ReadAllBytes which reads the files successfully and very fast and load it to the string. But after that it takes very long time to process the string line by line. Is there better way or faster way to do so.
Thank in advance.
You can use
File.ReadLines
, it will enumerate through lines of file:It will not load file at the first line. It will load it while looping through
lines
, so it's better way to read bigger files, than loading it at once.MSDN says in description of
File.ReadLines