public abstract class ThreadArray<T> where T : ThreadArrayConfig, new() 
  {
  }我对这行代码比较迷茫了··· 
那位大大能够详细解释下 class ThreadArray<T> where T : ThreadArrayConfig, new() 这个语法的含义么(其中ThreadArrayConfig是个一类)?

解决方案 »

  1.   

    【where T : ThreadArrayConfig, new()  】这个语法就是泛型类型参数的约束。
    表示T必须是继承自ThreadArrayConfig,并且拥有无参数的公共构造函数。
      

  2.   

    where T是对这个泛型类的约束,比如where T : ThreadArrayConfig,则就是T必须要是ThreadArrayConfig类或者继承了ThreadArrayConfig的类。
    new() 约束类型T必须具有无参的构造函数
      

  3.   

    ThreadArrayConfig是一个类型,可能是一个类,也可能是一个接口。
    new()告诉编译器,该T支持无参数构造,即可以T t = new T();
    where T,是用来约束T的。
      

  4.   

    ThreadArray<ThreadArrayConfig>如果是这样子写就规定死了类型,不可扩展了。  
    看看 泛型 的作用,类似模板, 实际上配置项是可扩展的
      

  5.   

    我临时写了一个点的集合器,
      看看是不是你这种用法?--对于其它用法我一时想不出来。///定义类
    //点
    public class Point
    {
    public int x { get; set; }
    public int y { get; set; }
    public Point(int x,int y)
    {
    this.x = x;
    this.y = y;
    }
    }
    //颜色
    public class objValue : Point
    {
    public object value {get;set; }
    public objValue(object value)
    :base(0,0)
    {
    this.value = value;
    }
    public objValue(object value,int x,int y)
    : base(x, y)
    {
    this.value = value;
    }
    public objValue()
    : base(0, 0)
    {
    this.value = null;
    }
    }
    //颜色点收集器。
    public  class Collection<T> where T : Point, new()
    {
    public List<T> value{get;set;}
    public void add(T t)
    {
    this.value.Add(t);
    }
    public int getCount()
    {
    return this.value.Count;
    }
    public bool remove(int index)
    {
    if (0 <= index && index < this.value.Count)
    {
    this.value.RemoveAt(index);
    return true;
    }
    else
    {
    return false;
    }
    }
    }
    //用法:
    Collection<objValue> valuePoints = new Collection<objValue>();
    valuePoints.add(new objValue("blue",1,2));//加入一点
    valuePoints.add(new objValue("red", 10, 10));//加入一点
    //....
    //移除第0个元素
    if (true == valuePoints.remove(0))
    { //成功
    }
    else
    {
    //失败
    }