Skip to main content
 首页 » 编程设计

c#之FileHelpers 有限制吗

2024年02月23日17kerrycode

我想知道当它从一个文件中读取一个流时,你能告诉它只取 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();