I've studied Covariant and Contravariant in C#. and below my code has an error.
object a = new object();
int b = 10;
a = b; // not error
Func<object> acO = () => new object();
Func<int> acI = () => 1;
acO = acI; // error
Error Message:
Cannot implicitly convert type 'System.Func' to type 'System.Func'.
I thought that if int -> object is possible, Func -> Func will be possible. but it is not.
I think value type will be copied to use when it is returned unlike reference type(object) and it can cause unintentional operation(like exception). Is my guess correct?
I'm looking forward to your wise answers. Thank you for reading.
From the Variance in Delegates (C#) docs:
A nice blog post diving into the topic by Eric Lippert: