Chef Boyarcaese
CSV Reader Issue
public class FlashcardService
{
// Using a library called CsvHelper to store and read flashcards from the CSV file
private readonly string _filePath = Path.Combine(Environment.CurrentDirectory, "Data", "flashcards.csv");
public List<Flashcard> LoadFlashcards()
{
// CsvReader allows for opening and reading the CSV file
using (var reader = new StreamReader(_filePath)) // Open file for reading
{
// Create a CsvReader instance using the StreamReader
var csvReader = new CsvReader((reader);
// Reads all records from the CSV and maps them to Flashcard objects
return csvReader.GetRecords<Flashcard>().ToList();
}
}
41 replies