Reading CSV file and storing values into an array

后端 未结 19 1821
猫巷女王i
猫巷女王i 2020-11-22 06:35

I am trying to read a *.csv-file.

The *.csv-file consist of two columns separated by semicolon (\";\").

I am able

19条回答
  •  庸人自扰
    2020-11-22 06:58

    You can do it like this:

    using System.IO;
    
    static void Main(string[] args)
    {
        using(var reader = new StreamReader(@"C:\test.csv"))
        {
            List listA = new List();
            List listB = new List();
            while (!reader.EndOfStream)
            {
                var line = reader.ReadLine();
                var values = line.Split(';');
    
                listA.Add(values[0]);
                listB.Add(values[1]);
            }
        }
    }
    

提交回复
热议问题