c# 4.0 - C# long data type unboxing issue -
we can cast int
long
.
why following piece of code gives run time error.
object o = 9; long = (long)o; console.writeline(i);
i new c#.
per this bit of documentation:
for unboxing of value types succeed @ run time, the item being unboxed must reference object created boxing instance of value type. attempting unbox null or reference incompatible value type result in invalidcastexception.
so, have unbox int
first , convert long
(an implicit conversion exists):
object o = 9; long = (int)o;
Comments
Post a Comment