C#: Semantics for generics?
- by Rosarch
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?