Why the following code get the error?
Invalid variance: The type parameter ‘T’ must be invariantly valid on
‘UserQuery.IItem<T>.GetList()’. ‘T’ is covariant.
public interface IFoo {}
public interface IBar<T> where T : IFoo {}
public interface IItem<out T> where T: IFoo
{
IEnumerable<IBar<T>> GetList();
}
The interfaces
IBarandIItemdo not agree on variance: in yourIBardeclaration, the T is not covariant, as there is nooutkeyword, whereas inIITemthe T is covariant.