using CsvHelper; using System.IO; var csvReader = new CsvReader(new StreamReader("data.csv")); csvReader.Configuration.HasHeaderRecord = true; foreach (var record in csvReader.EnumerateRecords()) { // Do something with the record Console.WriteLine(record[0]); Console.WriteLine(record[1]); }
using CsvHelper; using System.IO; var csvReader = new CsvReader(new StreamReader("data.csv")); csvReader.Configuration.HasHeaderRecord = true; var filteredRecords = csvReader.EnumerateRecords() .Where(record => record[0] == "USA"); foreach (var record in filteredRecords) { // Do something with the filtered record Console.WriteLine(record[0]); Console.WriteLine(record[1]); }This example demonstrates how to use the CsvReader EnumerateRecords method to filter records based on a specific condition. The code creates a new CsvReader object and sets the HasHeaderRecord property to true. It then uses the EnumerateRecords method to loop through each record in the file and filters the records based on the value of the first field. It prints the first two fields of each filtered record to the console. Package library: CsvHelper.