public class CSet<T>:List<T>
{
public int Union()
{
//temp是另外一个类的实体
othercls temp=new othercls(pA, pB, pC);
if (!this.Contains(temp))
{
this.Add(temp);
}
return this.Count;
}
}
我想做的是,如果T为othercls,则Union可以用,那么这个Union是该怎么定义的呢?
我试过 public int Union<othercls>() 像是有问题样,谢谢了。
{
public int Union()
{
//temp是另外一个类的实体
othercls temp=new othercls(pA, pB, pC);
if (!this.Contains(temp))
{
this.Add(temp);
}
return this.Count;
}
}
我想做的是,如果T为othercls,则Union可以用,那么这个Union是该怎么定义的呢?
我试过 public int Union<othercls>() 像是有问题样,谢谢了。
是不是要这样?
public class CSet<T>:List<T> where T:othercls
是不是要这样?
标准答案了。
限制了T必须为othercls或他的子类
:new()
为必须有无参构造函数.一共10分,顶还有分,僧多粥少阿
public class CSet<T>:List<T> where T:othercls