1

I'm working with CSV but all the tutorials I've read use 2D Lists.

private void cargaCSV()
    {
        List<string[]> values = new List<string[]>();

        var reader = new StreamReader(File.OpenRead(*my file*));
        while (!reader.EndOfStream)
        {
            string line = reader.ReadLine();
            values.Add(line.Split(';'));
        }
    }

My problem is my project works with 2D String Array.

I tried the following:

    string [,]  Data = values.ToArray();

I want to convert the 2d list into 2d array

Philip Kirkbride
  • 19,609
  • 34
  • 109
  • 213

2 Answers2

1

You don't have to typecast hard and old way.

Simply replace

string [,]  Data = values.ToArray();

With

var  Data = values.ToArray();

Now Data is two dimensional array of strings.

Saleem
  • 8,353
  • 2
  • 17
  • 33
1

If all the arrays have the same length, then you can do what you are doing and, after that, create and fill the array manually:

string[,] stringArray = new string[values.Count, values.First().Length]

for (int i = 0; i < values.Count; i++)
    row = values[i];
    for (int j = 0; j < row.Length; j++)
        string[i,j] = row[j];
    }
}
heltonbiker
  • 25,169
  • 21
  • 129
  • 235