Search code examples
.netvb.nettype-conversionctype

Convert vs. CType


I am somewhat confused about presence of two seemingly identical VB.NET functions: CType(args) and Convert.ToType(args). I'm fairly new to .NET and VB in general, so I'm not quite sure whether one of them is a VB6 legacy or they actually have different purposes / uses / limitations. Is one of the them newer / safer? Are there reasons to use one but not the other?

Cheers! = )


Solution

  • CType is from VB6 times and is not the best when it comes to efficiency. You should be able to use Convert.ToXxxx() methods for convertion and TryCast() and DirectCast() for casting instead of CType().