I have the following code:
static Func<object, string> s_objToString = (x) => x.ToString(); static Func<string, string> s_stringToString = s_objToString;
The second line compiles, but the third line does not compile with an error:
It is not possible to implicitly convert the type ' System.Func<object,string> ' to ' System.Func<int,string> '
Why is this?
I understand that with genetics, although the string is obtained from the object a List<string> not derived from List<object> , but here object to string works and object to int fails, why?
OK, let's say I understand why; Now the question is how to do it (otherwise, than to define the MyInt class in the int field, since Func<object,string> to Func<MyInt,string> )?
source share