当我发现问题时,我正在玩通用约束。除了它在编译时显示的错误提示外,我无法找到它的答案。
struct MyStruct
{
public void Get()
{
}
}
class MyClass
{
public void Get()
{
}
}
public class Stable<T> where T : MyStruct // NOT Allowed
{
}
public class Stable<T> where T : MyClass //Allowed
{
}
public class Stable<T> where T : struct //Allowed
{
}
public class Stable<T> where T : class //Allowed
{
}
最佳答案
结构默认是密封的,所以你不应该在这里使用泛型。
使用:
public class StableStruct : Stable<MyStruct>
{
}
关于c# - 无法在 C# 的通用约束中使用结构类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50130944/