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

What is .dbml file?

1 Answers  


What is executereader in c#?

1 Answers  


What is reference types in c#?

1 Answers  


What are the Types of configuration files and their differences

1 Answers   BirlaSoft,


If there are 2 interface IParentInterface & IChildInterface as follows. interface IParentInterface { void InterfaceMethod(); } interface IChildInterface : IParentInterface { void InterfaceMethod(); } Both the interface contains method with same name InterfaceMethod(). How InterfaceMethod() will be handled in IChildInterface as its deriving IParentInterface

3 Answers  


What namespaces are necessary to create a localized application?

2 Answers  


What is desktop application testing?

1 Answers  


what is collections and what is generics

4 Answers   Bally Technologies,


Explain the Scope of public/private/friend/protected/protected friend.

1 Answers   Rigel Networks, Wipro,


What is Private Constructor? and it’s use? Can you create instance of a class which has Private Constructor?

1 Answers  


Why array is faster than arraylist in c#?

1 Answers  


Why cannot you specify the accessibility modifier for methods inside the interface?

1 Answers  


Categories