-3

I have a list of list strings. And I want to convert it to 2D string.

I tried the following the code

IList<IList<string>> string2DList;
string[,] string2D = string2DList.ToArray();

but the above code gives an error on the second line that string2DList.ToArray() is the array of List.

3

1 Answer 1

-1

Does this help?

string[][] string2D = string2DList.Select(a => a.ToArray()).ToArray();

Sign up to request clarification or add additional context in comments.

3 Comments

I believe it was downvoted because it creates a nested array instead of a multidimensional array.
But if we understand the difference between [,] and [][]. string[,] is a rectangular array, while string[][] is known as a "jagged array". In this example its not possible to convert to rectangular array as we can never assure that each list has same length of child strings.
Hence why we need a minimal reproducible example @Bharat.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.