Hello everyone,
Could anyone let me know why compiler can not make runtime error report in the following code, other than throw cast exception during runtime?
[Code]
static void Main()
{
int i = 100;
object b = i;
long l = (long)b; // why compiler can not make type check here?
return;
}
[/Code]
thanks in advance,
George

Scott LysleRank #49 · 31K reputationPosted May 9, 2008, 8:52 AM EDT
George GeorgeRank #1,736 · 870 reputationPosted May 11, 2008, 12:18 AM EDT
What means "'checked' and trap the error"? Any documents?
regards,
George
Bechir BejaouiRank #144 · 15.9K reputationPosted May 11, 2008, 2:47 AM EDT
George GeorgeRank #1,736 · 870 reputationPosted May 11, 2008, 3:06 AM EDT
Thanks Bechir,
1.
"You can also check the cast using 'checked' and trap the error in a try catch block."
How to "trap the error" in a try catch block? Could you show me please?
2.
"You can also check the cast using 'checked' and trap the error in a try catch block."
What means 'checked'? A language feature of C# or a feature of VS?
3.
How to use generics to solve the unbox to wrong type issue?
regards,
George