I think you should be able to use a class like this:
public static void ReadCsv()
{
IEnumerable<People> records;
using (var streamReader = File.OpenText(@"C:/Samples/Vivek/ConsoleApp5/Paylocity.csv"))
using (var csvReader = new CsvReader(streamReader, CultureInfo.CurrentCulture))
{
records = csvReader.GetRecords<People>();
foreach (var record in records)
{
if (record.Id == record.Supervisor_ID)
{
Console.WriteLine($"{record.Id} {record.Supervisor_ID}");
}
}
}
}
public class People
{
public int Id { get; set; }
public string PreferredFirstName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Supervisor_ID { get; set; }
}
note that this is not a complete example, it is up to you to complete the class ...
If you get a header error, take a look at the documentation about
HeaderValidated here:
CsvHelper[
^]
You might need to use:
csvReader.Configuration.HasHeaderRecord = false;