检查这个有趣的方法,Linq To Text Files,非常好,你只需要一个IEnumerable<string>方法,产生每一个file.ReadLine(),然后你做查询.
这是另一篇更好地解释相同技术的文章.
using (TextReader rdr = new StreamReader(fullFilePath))
{
string line;
while ((line = rdr.ReadLine()) != null)
{
// use line here
}
}
Run Code Online (Sandbox Code Playgroud)
将变量"fullFilePath"设置为完整路径,例如.C:\ TEMP\myTextFile.txt