Lets say I have a Dictionary object:
Dictionary myDictionary<int, SomeObject> = new Dictionary<string, SomeObject>();
Now I want to iterate through the dictionary in reverse order. I can’t use a simple for loop because I don’t know the keys of the dictionary. A foreach is easy:
foreach (SomeObject object in myDictionary.Values) { // Do stuff to object }
But how can I perform this in reverse?
I’d use a SortedList instead of a dictionary. You can still access it by Key, but you can access it by index as well.
It’s worth noting that a sorted list stores key/value pairs sorted by key only.