我有两个抽象类如下:
public abstract class MyBaseClass<T>
{
private T ID;
private string Name;
private bool isActive;
protected MyBaseClass()
{
Initialize(0, String.Empty, false);
}
protected MyBaseClass(object ID, string Name, bool isActive)
{
Initialize(ID, Name, isActive);
}
protected virtual void Initialize(object ID, string Name, bool isActive)
{
Type t = typeof(T);
if(t == typeof(string)))
this.ID = (T)(object)ID.ToString();
else
this.ID = (T)ID
this.Name = Name;
this.isActive = isActive;
}
}
public abstract class MyList<TKey, TItem> where TItem : MyBaseClass<TKey> {}
T
和TKey
可以是string
或数字类型。
我在MyList上收到以下错误:
类型参数TItem继承冲突约束 'MyBaseClass'和'object'。
这个错误意味着什么,我该如何解决?