See Eric Lippert answer :
"Output" means that "T is used only in output positions." You use it in the entry position
(even if it is a Func delegate return type). If the compiler allowed this, you could write (in your example):
static void Main(string[] args) { var temp = new Temp<People>(); TestMethod(temp); } public static void TestMethod(ITemp<Organism> param) { param.SecondPrint(() => new Animal()); }
Call SecondPrint on Temp<People> , but passing a lambda that returns Animal .
I would remove the variance annotation on T :
interface ITemp<T> where T : Organism { void SecondPrint(Expression<Func<T>> parameter); }
and make TestMethod parametric in T :
public static void TestMethod<T>(ITemp<T> param) where T : Organism { }
source share