循环到IEnumberable列表中的特定值

时间:2018-12-20 09:01:48

标签: c# csv csvhelper

我正在使用csvHelper库来读取csv文件中的记录列表,并且想知道如何读取特定值或行中的列表。

My CSV file data:

123456
546879
258963
147852
654789
321654

当前我的代码如下:

Currently my code:
int controlid = 0; //This value is read from a file 

using (CsvReader csvread = new 
CsvReader(inputFilePath))
IEnumberable<dynamic> records = csvread.GetRecords<dynamic>();

 for (int i = controlid; i < records.Count(); i++)
 {
    customerID = records.ElementAt(i); // I get Arugument out of bounds error here
    console.writeLine(customerID);
    controlID++;

  }

1 个答案:

答案 0 :(得分:0)

using (CsvReader csvread = new 
CsvReader(inputFilePath))
IEnumberable<dynamic> records = csvread.GetRecords<dynamic>();
records.SkipWhile(e => e != controlid).ToList().ForEach(e =>
{
       console.writeLine(e);
}

我希望这会有所帮助。