Shaamil Ahmed
Shaamil Ahmed

Reputation: 378

IEnumerable<IEnumerable<T>> to string[][]

How do I cast a IEnumerable<IEnumerable<T>> to a string[][] or a List<string[]>?

I already tried .toArray and .SelectMany but they seem to create either string[] or List<IEnumerable<string>> which is not what I really want.

Upvotes: 2

Views: 305

Answers (1)

squill25
squill25

Reputation: 1208

You could use Select to map each inner IEnumerable<string> to a string[]:

string[][] arrayOfStringArrays = enumerable.Select(innerEnumerable => innerEnumerable.ToArray()).ToArray();

Upvotes: 5

Related Questions