I'm trying to perform a search on a column inside a CSV file, but cannot for the life of me figure out the best way to do it. I'm quite new to C# so most things I found were quite complicated.
The CSV file has three columns "id", "title" and "rating", and I want to search trough the title column.
I cam across a suggestion that I should turn the CSV into a list and then search through it.
This is the code I have so far for converting the file into a list:
var reader = new StreamReader(File.OpenRead(@"books.csv"));
List<string> listA = new List<string>();
List<string> listB = new List<string>();
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');
listA.Add(values[0]);
listB.Add(values[1]);
foreach (var column1 in listA)
{
Console.WriteLine(column1);
}
foreach (var column2 in listA)
{
Console.WriteLine(column2);
}
}
But I do not understand how it works and I get an error
Index was outside the bounds of the array
Could anybody point me in the right direction because I'm quite lost?