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

Define using statement in c#?

513


What is dao in c#?

488


What is bitwise operator in c#?

507


Write a sample code to write the contents to text file in c#?

479


What is expression tree in c#?

478






Which compiler switch creates an xml file from xml comments in the files in an assembly?

579


What is difference between tostring() vs convert.tostring() vs (string) cast

540


What is the and operator in c#?

479


What is the xml document structure?

470


what is boxing and unboxing?can we initialize unboxing directly?

492


What is parse method in c#?

450


What is a verbatim string literal and why do we use it?

473


Is list immutable in c#?

483


what is the difference between convert.tostring() and tostring() functions ?

568


What is xpath in c#?

480