<分区>
interface<T> where T : class
例如
public interface iSend<T> where T : class
上面的代码是什么意思?
为什么要用这个?
什么时候使用这个?
<分区>
interface<T> where T : class
例如
public interface iSend<T> where T : class
上面的代码是什么意思?
为什么要用这个?
什么时候使用这个?
最佳答案
在这里查看我的完整帖子:Constrain on custom generic type其中讨论了不同类型的通用约束
是引用类型约束
约束确保类型参数是引用类型。即类、接口(interface)、委托(delegate)、数组等。
interface iSend<T> where T : class
例子
Valid InValid
A<MyClass> A<int>
A<InterfaceME> A<float>
A<float[]>
注意: 应用多个约束时始终排在第一位。
关于c# - 接口(interface) <T> 其中 T : class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21778575/