Keys. ToList(); List<string> values = keys. Select(i => dicNumber[i]). ToList();
KeyValuePair is the unit of data stored in a Hashtable (or Dictionary ). They are not equivalent to each other. A key value pair contains a single key and a single value. A dictionary or hashtable contains a mapping of many keys to their associated values.
To convert a Dictionary<TKey, TValue>
to a List<KeyValuePair<TKey, TValue>>
you can just say
var list = dictionary.ToList();
or the more verbose
var list = dictionary.ToList<KeyValuePair<TKey, TValue>>();
This is because Dictionary<TKey, TValue>
implements IEnumerable<KeyValuePair<TKey, TValue>>
.
Using linq:
myDict.ToList<KeyValuePair<double, double>>();
Dictionary elements are KeyValuePair
items.
Like Jason said. But if you don't really need a list, then you can just cast it to an ICollection<TKey, TValue>
; because it implements this interface, but some parts only explicitly. This method performs better because it don't copy the entire list, just reuses the same dictionary instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With