我想寫一個SortedDictionary
的自定義比較器,其中鍵根據其類型進行排序。這可能嗎?比較SortedDictionary的鍵的類型
public class StateBase
{
// This is a base class I have to inherit from
}
SortedDictionary<StateBase, int> _stateDictionary =
new SortedDictionary<StateBase, int>(new StateComparer());
class StateComparer : IComparer<StateBase>
{
public int Compare(StateBase a, StateBase b)
{
// I'd like to sort these based on their type
// I don't particularly care what order they are in, I just want them
// to be sorted.
}
}
這些鍵將全部爲相同類型。你能澄清一下嗎? – Jon