类型参数继承冲突的约束

时间:2013-12-08 12:38:02

标签: c# constraints abstract-class

我有两个抽象类如下:

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> {}

TTKey可以是string或数字类型。

我在MyList上收到以下错误:

  

类型参数TItem继承冲突约束   'MyBaseClass'和'object'。

这个错误意味着什么,我该如何解决?

0 个答案:

没有答案