.net 2.0 SortedList(Of TKey, TValue) 类使用问题

来源:百度知道 编辑:UC知道 时间:2024/06/05 19:40:11
发生错误

未处理的“System.InvalidOperationException”类型的异常出现在 mscorlib.dll 中。

其他信息: 未能比较数组中的两个元素。

代码如下:

ServicerKey key = new ServicerKey(1, UserSessionKey.CreateSessionKey());
ServicerKey key1 = new ServicerKey(1, UserSessionKey.CreateSessionKey());

SortedList<ServicerKey, uint> list = new SortedList<ServicerKey, uint>();

list.Add(key, 1);
list.Add(key1, 2);

其中 ServicerKey 是一个类,类的申明如下:

/// <summary>
/// 用于方便查询客服列表的Key
/// </summary>
[Serializable]
public class ServicerKey
{
protected uint m_UserID;
protected string m_SessionKey;

public ServicerKey( uint userID )
{
m_UserID = userID;
}

public ServicerKey( string sessionKey )
{
m_Sessi

我的编译的结果还有一个
system.argumentexception:必须至少有一个对象实现IComparable
是不是你用泛型的时候忘记使用派生约束了,没有实现IComparable这个接口
因为你的代码没有贴全,我就只有这么猜测一下了,希望对你有帮助