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 |
Should I implement finalize on my class? Should I implement idisposable?
What is a formatter in .net?
i have an array of 10 objects whose values are from 1-10 randomly inserted. i have deleted one array object. tell me what is that value? write the logic of it.
2 Answers Deloitte, Srp Khanij,
What application do you use to install a Windows service?
What is data type and how many types of data types are in .NET ?
How to store and retrieve images in SQL server database through VB.NET?
How will you make .NET programs work in Linux ?
Explain memory-mapped files.
What is the lapsed listener problem?
Please explain what garbage collection is and how it works. Provide a code example of how you can enforce garbage collection in .net?
C++ & C# differences ?
How do you turn off cookies for one page in your site?