How to read a CSV file and store the values into an array in C#?

A CSV file is a comma-separated file, that is used to store data in an organized way.

Data.csv
A,B,C

Example

using System;
using System.IO;
using System.Collections.Generic;

   class Program
    {
        public static void Main()
        {
            string FilePath = @"C:\Sample\Data.csv";

            StreamReader reader = null;

            if (File.Exists(FilePath))
            {
                reader = new StreamReader(File.OpenRead(FilePath));

                List<string> listData = new List<string>();

                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();

                    var values = line.Split(',');

                    foreach (var item in values)
                    {

                        listData.Add(item);

                    }
                    foreach (var row1 in listData)
                    {

                        Console.WriteLine(row1);

                    }
                }
            }
            else
            {
                Console.WriteLine("File doesn't exist");
            }
            Console.ReadLine();
        }
    }

Output

A
B
C