public static SortedDictionary <TK, TV> Invert <TK, TV>(this SortedDictionary <TK, TV> dictionary)
        {
            var comparer = dictionary.Comparer;
            var inverted = new StandardComparer <TK>(
                (a, b) => - comparer.Compare(a, b));

            return(new SortedDictionary <TK, TV>(dictionary, inverted));
        }
Exemple #2
0
        public OrderedDictionary <TK, TV> Invert()
        {
            var comparer = _keyComparer;
            var inverted = new StandardComparer <TK>(
                (a, b) => - comparer.Compare(a, b));

            var invertedKeyList = new List <TK>(_keyList);
            var invertedValList = new List <TV>(_valList);

            invertedKeyList.Reverse();
            invertedValList.Reverse();

            return(new OrderedDictionary <TK, TV>(
                       invertedKeyList,
                       invertedValList,
                       inverted));
        }