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

Is c and c# the same?

707


Write a program to find the angle between the hours and minutes in a clock

715


What does string format do?

681


How do you specify a custom attribute for the entire assembly (rather than for a class)?

759


What does == mean in c sharp?

720


What is strongly typed in c#?

689


What does static mean in c sharp?

830


Why do we need singleton class in c#?

751


Can a dictionary have duplicate keys c#?

711


What does typeof return c#?

737


How can you set image source dynamically from c# application to ”test.png” file?

872


Difference between value and reference type. What are value types and reference types?

762


What is difference between internal and protected internal in c#?

706


How does it work?

713


What is a di class?

799