Explicit Casting Problem

…衆ロ難τιáo~ 提交于 2019-11-27 16:30:35

Another generics covariant problem...

Generic types in .NET are not covariant or contravariant - IContainer<ItemA> (which is what AContainer is) is not a subclass of IContainer<IItem> - there is no valid cast between the two. This will be fixed in C# 4.

If you want to use AContainer to be an IContainer<IItem>, you need to implement this interface as well:

public class AContainer : IContainer<ItemA>, IContainer<IItem>

You may implement it explicitly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!