ashishraj14
Programmer
What is the fundamental difference between CType, DirectCast, Parse, Convert different?
thanks
thanks
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Dim a As Object
Dim b As Object
Dim i As Integer
a = 1 [COLOR=green]'the object [b]a[/b] contains an integer[/color]
b = "1" [COLOR=green]'the object [b]b[/b] contains a string[/color]
i = DirectCast(a, Integer) [COLOR=green]'Good: a contains an integer[/color]
i = DirectCast(b, Integer) [COLOR=green]'Bad: b contains a string[/color]
i = CType(b, Integer) [COLOR=green]'Good: CType [b]will[/b] convert a string to an integer[/color]
microsoft said:CType is compiled inline, meaning the conversion code is part of the code that evaluates the expression. Execution is faster because there is no call to a procedure to accomplish the conversion.