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
George GeorgePosted May 11, 2008, 7:06 AM
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
Bechir BejaouiPosted May 11, 2008, 6:47 AM
George GeorgePosted May 11, 2008, 4:18 AM
What means "'checked' and trap the error"? Any documents?
regards,
George
Scott LyslePosted May 9, 2008, 12:52 PM