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

Difference between ByVal and ByRef?

5 Answers   Microsoft,


What is default value of enum c#?

0 Answers  


Can an abstract class inherit from another abstract class c#?

0 Answers  


Tell me the difference between call by value and call by reference.

0 Answers   NIIT,


What is the difference between readonly and const

4 Answers   Emphasis,






What do you mean by directing?

0 Answers  


How many types of constructors are available in c#?

0 Answers  


Can we have multiple threads in one app domain?

0 Answers  


what is be the overhead, if i use binary transmission. and will it be sent using xml text or how ?

0 Answers  


Is c# and c same?

0 Answers  


How many types of interface are there in c#?

0 Answers  


what does static void Main(string[] args) in C# mean????????

5 Answers   ssinformatics,


Categories