Difference between directcast and ctype.

Submitted by: Administrator
Anser1
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.

Answer2
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.
Submitted by: Administrator

Read Online C# (Sharp) Programming Language Job Interview Questions And Answers