where T : System.ValueType
? // Defined in a .Net class
public void bar<T>(T a) where T : ValueType {...}
// Defined in my class
public void foo<T>(T a) where T : ValueType
{ bar<T>(a); }
// Defined in my class
public void foo<T>(T a) where T : struct
{ bar<T>(a); }
使用有两个区别
where T : struct
where T : ValueType
T
成为 ValueType
本身,这是一个引用类型。 T
为可空值类型 Nullable<T>
有点奇怪,因为它既不满足 where T : struct
也不是 where T : class
约束。where T : struct, System.Enum
关于c# - 为什么我不能使用 System.ValueType 作为泛型约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1854625/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |