where用于约束泛型
public class MyGenericClass<T> where T:IComparable {
}
表示类型T
只能是IComparable
的子类
public class MyGenericClass <T> where T: IComparable, new()
new()
只能出现在末尾
new()
的意思就是说该类必须有公共的无参构造函数
where用于约束泛型
public class MyGenericClass<T> where T:IComparable {
}
表示类型T
只能是IComparable
的子类
public class MyGenericClass <T> where T: IComparable, new()
new()
只能出现在末尾
new()
的意思就是说该类必须有公共的无参构造函数