A more appropriate solution is to do what you're already doing by sorting when you read from the dictionary rather than keeping it sorted in memory. I would suggest caching the sorted result as a List though to reduce the amount of overhead.


If you have to repeatedly sort by the items in the value part of a IDictionary, you're doing it wrong, at least with large datasets.

Use a container that either allows you to store the data at insertion time in the correct order (e.g. SortedList, using a custom comparer) or a List that you then .Sort on an as-needed basis (again, with a custom comparer). It really depends on how often you are adding data and how often you need to re-sort. You'd have to measure for this.

Related Articles