I have the following code:
static Func<object, string> s_objToString = (x) => x.ToString();
static Func<string, string> s_stringToString = s_objToString; //compiles
static Func<int, string> s_intToString = s_objToString; //error
The second line compiles but the third line fails to compile with error:
Cannot implicitly convert type '
System.Func<object,string>' to 'System.Func<int,string>'
Why is that?
I understand that with genetics although string is derived from object a List<string> does not derive from List<object>, but here object to string works and object to int fails, why?
OK let's say I understood why; the question now is there a way around it (other then defining MyInt class to box int because Func<object,string> to Func<MyInt,string> works)?