Casting DataTypes with DirectCast, CType, TryCast
Posted
by Alex Essilfie
on Stack Overflow
See other posts from Stack Overflow
or by Alex Essilfie
Published on 2010-04-24T07:14:50Z
Indexed on
2010/04/24
7:23 UTC
Read the original article
Hit count: 305
Ever since I moved from VB6 to VB.NET somewhere in 2005, I've been using CType to do casting from one data type to another. I do this because it is simply faster, used to exist in VB6 and I do not know why I have to be using DirectCast if there is apparently no difference between them.
I use TryCast once in a while because I understand that sometimes casting can fail. I however cannot get the difference between CType and DirectCast.
Can anyone tell me the difference in plain simple English what the difference the two (CType and DirectCast)? Adding examples of where to use what as well would be helpful.
Thanks.
© Stack Overflow or respective owner