dictionary class : SortByKey(bool) method

Description

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

Syntax

dictionaryInstance.SortByKey(bool order)

Arguments

ClassNameDescription
boolorderSort order.

Return value

ClassDescription
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.

Notes

This method is added in Ver 1.1.0.0.

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

None

Copyright © Rice All rights reserved.