Florian Florian - 6 months ago 38
C# Question

How to get dictionary values as a generic list

I just want get a list from Dictionary values but it's not so simple as it appears !

here the code :

Dictionary<string, List<MyType>> myDico = GetDictionary();
List<MyType> items = ???

I try :

List<MyType> items = new List<MyType>(myDico.values)

But it does not work :-(


Off course, myDico.Values is List<List<MyType>>.

Use Linq if you want to flattern your lists

var items = myDico.SelectMany (d => d.Value).ToList();