directcast(123.34,integer) - should it throw an error? Why
or why not?

Answers were Sorted based on User's Feedback



directcast(123.34,integer) - should it throw an error? Why or why not? ..

Answer / 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

directcast(123.34,integer) - should it throw an error? Why or why not? ..

Answer / debasis sengupta

directcast(123.34,integer) would throw an InvalidCast
exception as the runtime type since it requires the run-
time type of an object variable to be same as the specified
type. In this case runtime type of 123.34 (double) doesn?t
match with integer.

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C Sharp Interview Questions

Why are strings immutable c#?

0 Answers  


What I can do with c#?

0 Answers  


Does c# support multiple inheritance (mi)?

0 Answers  


What do you understand by an Implicit Variable?

0 Answers   CGI,


What is static and use of it?

0 Answers  


What is anonymous class in c#?

0 Answers  


What is func c#?

0 Answers  


How do I format a string in c#?

0 Answers  


When a switch is said to be congested?

0 Answers   Wipro,


What is difference between write and writeline?

0 Answers  


What are destructors in C#?

1 Answers   TryTechnicals Pvt Ltd,


without modifying source code if we compile again, will it be generated MSIL again?

0 Answers  


Categories