Today I ran into a problem, and I did not quite understand why this would not work.
The following code example will work:
static void Main(string[] args) { int i32 = 10; object obj = i32; long i64 = (long)obj; }
This will throw an InvalidCastException. Why is this not working? Is C # smart enough to know that an object is really of type int?
I already came up with a workaround, but I'm curious why the above code example didn't work in the first place.
Thanks Tim
casting c #
Tim
source share