I have a SortedDictionary, the key is a int value and the matching value to each key is a class object. The class contains a int and a two datetime variable.
I need
Sorted Dictionary will always sort on the key, so there is no way to re-arrange it's data so they are sorted on anything other that the key. What you can do is get the data into another structure (some kind of IOrderedEnumerable
) where they can be sorted on things other that the key.
If you want to discard the keys and just get the values then
var sortedValues = dictionary.Values.OrderBy(busDetail => busDetail.InTime);
will work, and the type of sortedValues will be IOrderedEnumerable
.
If you still need to keep both the keys and values, you could do:
var sortedElements = dictionary.OrderBy(kvp => kvp.Value.InTime);
which will return a IOrderedEnumerable
.
You can that foreach
on any of these two collections, or you could bind them to a grid's datasource.