开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜