There is following code:
int intNumber1 = 100;
object intNumber2 = 100;
bool areNumberOfTheSameType = intNumber1.GetType() == intNumber2.GetType(); // TRUE
bool areEqual = intNumber1.Equals(intNumber2); // TRUE
long longNumber1 = (long) intNumber1; // OK
long longNumber2 = (long) intNumber2; // InvalidCastException. Why?
The question is: Why second cast doesn’t work? I realize that it might be because object doesn’t have explicit cast method to long, but if we look at its type on runtime it is Sustem.Int32. Any thoughts?
P.S. If I put "var" or "dynamic" instead of "object" it works
Thank you.