我有一个1 GB的文本文件,我需要逐行阅读.最好和最快的方法是什么?
private void ReadTxtFile()
{
string filePath = string.Empty;
filePath = openFileDialog1.FileName;
if (string.IsNullOrEmpty(filePath))
{
using (StreamReader sr = new StreamReader(filePath))
{
String line;
while ((line = sr.ReadLine()) != null)
{
FormatData(line);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在FormatData()
我检查线必须以一个字相匹配,并基于该增量的整数变量的起始字.
void FormatData(string line)
{
if (line.StartWith(word))
{
globalIntVariable++;
}
}
Run Code Online (Sandbox Code Playgroud) c# ×1