Explicitly create new KeyValuePair<T,V>
elements from the dictionary, then make a list of it:
internal List<KeyValuePair<T, V>> ToList()
{
return collection.Select(kvp => new KeyValuePair<T,V>(kvp.Key, kvp.Value).ToList();
}
Should perform the action you want.
Edit I would've expected your code to work as well. Could be that a Dictionary's .ToList()
method does something similar to .Select(x => x.Value)
as opposed to returning a List<KeyValuePair<X,Y>>
.
But that'd just be my guess.