What's the fastest way to read a text file line-by-line?

前端 未结 8 2066
情歌与酒
情歌与酒 2020-11-22 02:51

I want to read a text file line by line. I wanted to know if I\'m doing it as efficiently as possible within the .NET C# scope of things.

This is what I\'m trying so

8条回答
  •  终归单人心
    2020-11-22 03:13

    If the file size is not big, then it is faster to read the entire file and split it afterwards

    var filestreams = sr.ReadToEnd().Split(Environment.NewLine, 
                                  StringSplitOptions.RemoveEmptyEntries);
    

提交回复
热议问题