grigorij89
grigorij89

Reputation: 33

Get second item from Tuple which is List<T>

How can I get List<IMyType> from List<Tuple<int, List<IMyType>>>

var result = alg.Result; // Result return List<Tuple<int, List<IMyType>>>
List<IMyType> list = ???

Upvotes: 1

Views: 2950

Answers (2)

zmbq
zmbq

Reputation: 39013

@Servy's answer is the best way to do that. Just keep in mind that if you don't remember the LINQ way of doing things, you can always do it the old way:

var list = new List<IMyType>();
foreach(var tuple in result)
    list.AddRange(tuple.Item2);

Upvotes: 2

Servy
Servy

Reputation: 203814

SelectMany is used to transform each item in the collection to a sequence of something else, and then to flatten that sequence:

var flattenedSequence = list.SelectMany(pair => pair.Item2);

Upvotes: 4

Related Questions