dictionary class : SortByKey(bool) method


Gets a new dictionary which the caller dictionary is sorted by key.


dictionaryInstance.SortByKey(bool order)


boolorderSort order.

Return value

some dictionaryA new dictionary that is sorted.

Sample code

dictionary{int} orgDic = new dictionary{int}();

orgDic.Add("c", 1);

orgDic.Add("a", 2);

orgDic.Add("b", 3);

dictionary{int} ascDic = orgDic.SortByKey(true);

// order of the ascDic is "a"/2, "b"/3, "c"/1.

dictionary{int} descDic = orgDic.SortByKey(false);

// order of the descDic is "c"/1, "b"/3, "a"/2.


This method is added in Ver

If the argument is true, the returned dictionary is sorted in ascending order.

If the argument is false, the returned dictionary is sorted in descending order.

Returns a new dictionary that is sorted by key. The order of the caller dictionary does not change.

The returned dictionary is a shallow copy of the caller dictionary. That is, the caller and the returned dictionary refer to the same element.

Links for reference


Copyright © Rice All rights reserved.