Casting DataTypes with DirectCast, CType, TryCast
- by Alex Essilfie
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.