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


Please Help Members By Posting Answers For Below Questions

Does c# support #define for defining global constants?

794


What is an array? Give the syntax for a single and multi-dimensional array?

685


Explain the difference between // comments, /* */ comments and /// comments?

691


What is the purpose of reserved word using in c#?

676


How do I create a delegate/multicastdelegate?

750


If a child class instance is created, which class constructor is called first - base class or child class?

708


What is a reference type c#?

710


What is the difference between select and selectmany?

635


What is overloading with example?

714


Explain how to parse a datetime string?

688


What is difference between const and static in c#?

685


What is the components of window?

687


Is there any sample c# code for simple threading?

724


How do you prevent a method from being overridden in c#?

662


Can abstract class have constructor in c#?

707