c# - FileHelpers 有限制吗?

标签 c# filehelpers

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

相关文章:

c# - 如何使用 Dispose() 方法处理某些类型(如 Image)

c# - ConcurrentDictionary 添加或更新列表

c# - 如何避免以下重复代码?

c# - 如何使用 FileHelper 库为迭代字段创建客户类

visual-studio-2010 - 我通过 Nuget 添加了 `Marcos Melis Filehelpers` 并且收到了一个我不明白的警告,这是什么意思?

c# - 如何使用 .NET Core 配置框架将连接字符串放置到 json 配置文件中?

c# - 如何从字符串中删除回车符、换行符、空格

c# - FileHelpers 中的多个日期如何?

c# - 调用 FileHelperEngine 构造函数时 PresentationFramework.dll 中的 XamlParseException

c# - 如何使用 C#/FileHelpers ExcelNPOIStorage 从 Excel 文件中提取数据