我想知道当它从一个文件中读取一个流时,你能告诉它只取 x 行吗?假设你想要文件中的 100 行,你可以告诉它只取前 100 行(忽略第一行,因为它是标题)。即使文件有 200 行?
最佳答案
您可以使用 FileHelperAsyncEngine一个一个地处理记录。
FileHelperAsyncEngine engine = new FileHelperAsyncEngine(typeof(Customer));
engine.BeginReadFile("TestIn.txt");
int recordCount = 0;
foreach (Customer cust in engine)
{
// your code here
Console.WriteLine(cust.Name);
recordCount++;
if (recordCount > 100)
break; // stop processing
}
engine.Close();
关于c# - FileHelpers 有限制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9105222/