Error casting object? to int. #7302
Unanswered
AlfonsByRecognize
asked this question in
Q&A
Replies: 2 comments 2 replies
-
The bottom example is a runtime cast. And Because a uint is not an int, the runtime fails to cast. The top example, is not a runtime-cast. It is a "c# conversion", and c# has special rules on what to do here when the types are statically known. |
Beta Was this translation helpful? Give feedback.
2 replies
-
Casting from object to value type is unboxing. It's a different type of cast than numeric casting. C# doesn't use C++-style cast operators to distinguish different casts, but only uses C-style casts. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We have the following code:
The first 2 lines doesnt throw an error, the 2nd 2 lines throw 'Unable to cast object of type 'System.UInt32' to type 'System.Int32''. Can someone explain me why?
Beta Was this translation helpful? Give feedback.
All reactions