Why is this an invalid variance?

Viewed 529

Exact code I'm trying to build:

    public interface IMapContainer<out T> where T : MapRoomBase
    {
        String GetName();

        IEnumerable<T> GetRooms();
    }

I'm getting this error: Invalid variance: The type parameter 'T' must be invariantly valid on 'MapLibrary.IMapContainer.GetRooms()'. 'T' is covariant.

I was under the impression that this would be valid since IEnumerable simply returns the items, and none can be added. Why is this not safe + valid?

1 Answers
Related