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>() 像是有问题样,谢谢了。

解决方案 »

  1.   

    public class CSet<T>:List<T> where T:othercls
    是不是要这样?
      

  2.   

    danjiewu(阿丹) ( ) 信誉:100  2007-08-31 12:52:36  得分: 0  
     
     
       public class CSet<T>:List<T> where T:othercls
    是不是要这样?
      
     
    标准答案了。
      

  3.   

    就是楼上那样
    限制了T必须为othercls或他的子类
    :new()
    为必须有无参构造函数.一共10分,顶还有分,僧多粥少阿
      

  4.   

    谢谢各位。非常感谢,分就这么点,实在对不起了~特别感谢,danjiewu(阿丹) ( ) 信誉:100  2007-08-31 12:52:36  得分: 0  
     
     
       public class CSet<T>:List<T> where T:othercls