© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
40 replies
Gunna

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();
        }
    }
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();
        }
    }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Best CSV reader/writer library?
C#CC# / help
3y ago
❔ XML/CSV data reader and Local database
C#CC# / help
3y ago
❔ Csv textfieldparser
C#CC# / help
3y ago