You can give SortedDictionary
an IComparer<TKey>
on construction. You just need to provide one which reverses the order. For example:
public sealed class ReverseComparer<T> : IComparer<T>
{
private readonly IComparer<T> original;
public ReverseComparer(IComparer<T> original)
{
// TODO: Validation
this.original = original;
}
public int Compare(T left, T right)
{
return original.Compare(right, left);
}
}
Then:
var dictionary = new SortedDictionary<int, string>(
new ReverseComparer<int>(Comparer<int>.Default));