When a value type is boxed, it is placed inside an untyped reference object.
So what causes the invalid cast exception here?
long l = 1;
object obj = (object)l;
double d = (double)obj;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, it’s not placed in an untyped object. For each value type, there’s a boxed reference type in the CLR. So you’d have something like:
That boxed type isn’t directly accessible in C#, although it is in C++/CLI. Obviously that knows the original type. So in C# you have to have a compile-time type of
objectfor the variable but that doesn’t mean that’s the actual type of the object.See the ECMA CLI spec or CLR via C# for more details.