大文件读取方法(C#)

之前都是用StreamReader.ReadLine方法逐行读取文件,自从.NET4有了File.ReadLines这一利器,就再也不用为大文件发愁了。

File.ReadLines在整个文件读取到内存之前就提供 IEnumerator 对象供程序操作,且回传对象IEnumerator更易于操作。因此File类的ReadLines方法特别适合操作大型文件。

	var Fi = from line in File.ReadLines(openFileDialog1.FileName,Encoding.Default)
             where line.ToLower().Contains("happy")
             select new
             {
                 Line = line
             };

  

原文地址:https://www.cnblogs.com/globalwatch/p/3343341.html