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
Explain data types in c#?
What is string class in c#?
How many dimensions can an array have?
What is reflection in c#?
Is object an int c#?
Explain clr in brief.
Why is c# a good programming language?
What is better C# or VB.NET?
How to exclude a property from xml serialization?
How many static constructors are allowed in a class?
Why do we need to override in c#?
What is public, private, protected, internal and internal protected?
Explain the difference between event and a delegate in c#?
What is the difference between delegates and events in c#?
What is the use of 0 in c#?