C# Template as base type? if not . how?
class Beta : IBeta
class AlphaBeta<TBeta&开发者_运维技巧gt; : TBeta
where Tbeta : IBeta
Tbeta needs to be a type... compiler errr.
how can I get AlphaBeta to be a Beta?
ty
You can't do that - generics in .NET aren't the same as templates in C++.
You can give AlphaBeta
a member variable of type TBeta
, but you can't make it derive from TBeta
.
If you can give more information about what you're trying to do at a "bigger picture" level, we may be able to give more help. Would implementing IBeta
be acceptable instead?
I would suggest
class AlphaBeta<T> : Beta
where T : IBeta
Because T is the C# generic type handler. You then use constraints to force T to be a class that inherits the IBeta class.
精彩评论