Для начала вы можете изучить основы парсера csv онлайн. Я предпочитаю создавать собственные, исходя из потребностей, вместо использования сторонних библиотек.
class Program
{
/// <summary>The type that can be used to map csv data</summary>
class CsvType
{
public string ID { get; set; }
public string State { get; set; }
public string Country { get; set; }
public string Population { get; set; }
}
static void Main()
{
//csv line data to clr object transformation
Func<string[], CsvType> transform = splittedProperties =>
new CsvType
{
ID = splittedProperties[0],
State = splittedProperties[1],
Country = splittedProperties[2],
Population = splittedProperties[3]
};
//Csv line to splitted based on some character
//For demonstration purpose i used comma.
//please take care when the columns data itself can contain splitter as value
Func<string, string[]> splitter = line => line.Split(",");
IEnumerable<CsvType> data = CsvParser<CsvType>("filepath", transform, splitter)
.Where(x => x.State == "Your value");// U can apply an conditiion to filter and other opeartions too
}
static IEnumerable<T> CsvParser<T>(string filePath,
Func<string[], T> transform,
Func<string, string[]> csvSplitter)
{
return File.ReadLines(filePath).Select(csvSplitter).Select(transform);
}
}