Reading CSV file and storing values into an array

后端 未结 19 1762
猫巷女王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 07:10

    LINQ way:

    var lines = File.ReadAllLines("test.txt").Select(a => a.Split(';'));
    var csv = from line in lines
              select (from piece in line
                      select piece);
    

    ^^Wrong - Edit by Nick

    It appears the original answerer was attempting to populate csv with a 2 dimensional array - an array containing arrays. Each item in the first array contains an array representing that line number with each item in the nested array containing the data for that specific column.

    var csv = from line in lines
              select (line.Split(',')).ToArray();
    

提交回复
热议问题