C#: Semantics for generics?

Posted by Rosarch on Stack Overflow See other posts from Stack Overflow or by Rosarch
Published on 2010-04-15T20:44:53Z Indexed on 2010/04/15 20:53 UTC
Read the original article Hit count: 545

Filed under:
|
|
|

I have a list:

private readonly IList<IList<GameObjectController>> removeTargets;

PickUp inherits from GameObjectController. But when I try this:

public IList<PickUp> Inventory

// ... 

gameObjectManager.MoveFromListToWorld(this, user.Model.Inventory);

I get a compiler error:

cannot convert from 'System.Collections.Generic.IList' to 'System.Collections.Generic.IList'

Why does this occur? Shouldn't this be fine, since PickUp is a subclass of GameObjectController? Do I need something like Java's Map<E extends GameObjectController>?

Earlier, I was having a similar problem, where I was trying to implicitly cast inventory from an IList to an ICollection. Is this the same problem?

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics