Explicit Casting Problem

后端 未结 3 1741
轻奢々
轻奢々 2020-12-04 04:22
// The Structure of the Container and the items
public interface IContainer  where TItem : IItem
{

}

public class AContainer : IContainer         


        
3条回答
  •  悲哀的现实
    2020-12-04 04:50

    Another generics covariant problem...

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

提交回复
热议问题