Those are all slightly different, and generally have an acceptable usage.
var.
ToString
()
is going to give you the string representation of an object, regardless of what type it is. Use this ifvar
is not a string already.CStr
(var)
is the VB string cast operator. I’m not a VB guy, so I would suggest avoiding it, but it’s not really going to hurt anything. I think it is basically the same asCType
.CType
(var, String)
will convert the given type into a string, using any provided conversion operators.DirectCast
(var, String)
is used to up-cast an object into a string. If you know that an object variable is, in fact, a string, use this. This is the same as(string)var
in C#.TryCast
(as mentioned by @NotMyself) is likeDirectCast
, but it will returnNothing
if the variable can’t be converted into a string, rather than throwing an exception. This is the same asvar as string
in C#. TheTryCast
page on MSDN has a good comparison, too.