【发布时间】:2012-07-05 08:33:32
【问题描述】:
我想为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.
}
}
【问题讨论】:
-
所有键都属于同一类型。你能澄清一下吗?
标签: c# types dictionary comparator