Is int assignable from char?

.net, c#, reflection

Solution

Isn't this a contradiction?

Nope. C# provides an implicit conversion from `char` to `int`, but if you look at the documentation for `Type.IsAssignableFrom` it states for the return value:

true if c and the current Type represent the same type, or if the current Type is in the inheritance hierarchy of c, or if the current Type is an interface that c implements, or if c is a generic type parameter and the current Type represents one of the constraints of c, or if c represents a value type and the current Type represents `Nullable<c>`. false if none of these conditions are true, or if c is null.

None of those conditions is true, so it returns `false`.

Problem

I note that ``` int number = 'a'; ``` Is a sound C# statement But that the expression ``` typeof(int).IsAssignableFrom(typeof(char)) ``` Returns false. Isn't this a contradiction?

Original source

Related problems