在sortedlist队列中,queue.value [0]给出min键的对应值.如果我想让它给出最大键值?
我必须重写icomparer吗?
fix*_*gon 11
是的,你必须重写比较器
字符串作为键的示例:(刚刚交换x.CompareTo(y)过y.CompareTo(x))
private class InvertedComparer : IComparer<String>
{
public int Compare(string x, string y)
{
return y.CompareTo(x);
}
}
Run Code Online (Sandbox Code Playgroud)
和电话:
SortedList<string, Object> list = new SortedList<string, Object>(new InvertedComparer());
Run Code Online (Sandbox Code Playgroud)