How to inherit from a generic parameter?

后端 未结 4 1993
广开言路
广开言路 2020-12-11 14:23

I\'m basically wanting to do this:

class UILockable : T
    where T : UIWidget
{
}

However, this doesn\'t work. I\'ve seen people

4条回答
  •  攒了一身酷
    2020-12-11 15:12

    You can't inherit from the generic type parameter. C# generics are very different from C++ templates. Inheriting from the type parameter requires the class to have a completely different representation based on the type parameter, which is not what happens with .NET generics. They are identical at the IL and native level (for all reference type arguments).

提交回复
热议问题