What is the Difference between directcast and ctype?
Answers were Sorted based on User's Feedback
Answer / aravindreddy
DirectCast requires the run-time type of an object variable
to bethe same
as the specified type.The run-time performance
ofDirectCast is better
than that of CType, if the specified type and the run-time
typeof the
expression are the same.
Ctype works fine if there is a valid conversion defined
between the
expression and the type.
| Is This Answer Correct ? | 16 Yes | 2 No |
The difference between the two keywords is that CType
succeeds as long as there is a valid conversion defined
between the expression and the type, whereas DirectCast
requires the run-time type of an object variable to be the
same as the specified type. If the specified type and the
run-time type of the expression are the same, however, the
run-time performance of DirectCast is better than that of
CType. DirectCast throws an InvalidCastException error if
the argument types do not match.
| Is This Answer Correct ? | 12 Yes | 3 No |
Answer / suresh
Direct cast: Supports only reference type conversions
it throws exception
CType cast: supports only Value type conversions
| Is This Answer Correct ? | 7 Yes | 22 No |
Give An example of a ctype and directcast.
Why do we use the “using” statement?
What's wrong with a line like this? Datetime.parse(mystring);
Which among the following two is best and why? Abstract Class and Interface. What is the major difference in between those two except the discrete methods and methods with function definition.
what is the default value of CHAR type?in C# using asp.net?
What is the Difference between imperative and interrogative code?
What does SCM do?
What?s the Unix name for a Windows service equivalent?
Is there built-in support for logging?
I am constantly writing the drawing procedures with system.drawing.graphics, but having to use the try and dispose blocks is too time-consuming with graphicsobjects. Can I automate this?
What is a windows process in .net?
Major role of CLR for CAS