I'm struggle with this little piece of code
static T Read<T>(object rawValue)
{
if (rawValue is int )
{
int n = 5 ;
return (T) n ; // Compilation error
}
return default(T) ;
}
while :
static T Read<T>(object rawValue)
{
if (rawValue is int )
{
int n = 5 ;
return (T) (object) n ; // Compile OK
}
return default(T) ;
}
Why do I need to pre cast it to object to make it compile?