I was reading unboxing and came across this code:
object obj = 22;
long l = (long)obj;
when I ran this code, it throws an exception InvalidCastException
I do not understand why?
For example Microsoft documentation on Boxing and Unboxing shows similar example that works:
int i = 123;
// The following line boxes i.
object o = i;
o = 123;
i = (int)o; // unboxing