DirectCast和CType还是有点区别

it2025-03-13  19

差别: 只要定义了表达式与类型之间的有效转换, CType 即可成功, 而 DirectCast 则要求对象变量的运行时类型与指定的类型相同。 性能:      如果表达式的指定类型和运行时类型相同,则 DirectCast 的运行时性能比 CType 的运行时性能好。

        Dim Q As Object = 2.37                      ' Requires Option Strict to be Off.

        Dim I As Integer = CType(Q, Integer)        ' Succeeds.

        Dim J As Integer = DirectCast(Q, Integer)   ' Fails.

转载于:https://www.cnblogs.com/HappyQQ/archive/2008/01/28/1056805.html

相关资源:数据结构—成绩单生成器
最新回复(0)