directcast(123.34,integer) - should it throw an error? Why
or why not?
Answer Posted / debasis sengupta
directcast(123.34,integer) would throw an InvalidCast
exception since it requires the runtime type of the object
variable to be same as the specified type. In this case
runtime type of 123.34 (double) doesn?t match with integer.
but for ctype(123.34,integer) - it would work fine. As the
runtime type of 123.34 would be double, and Double can be
converted to Integer.
Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
Does c# support #define for defining global constants?
What is an array? Give the syntax for a single and multi-dimensional array?
Explain the difference between // comments, /* */ comments and /// comments?
What is the purpose of reserved word using in c#?
How do I create a delegate/multicastdelegate?
If a child class instance is created, which class constructor is called first - base class or child class?
What is a reference type c#?
What is the difference between select and selectmany?
What is overloading with example?
Explain how to parse a datetime string?
What is difference between const and static in c#?
What is the components of window?
Is there any sample c# code for simple threading?
How do you prevent a method from being overridden in c#?
Can abstract class have constructor in c#?