DirectCast won't work for this example - it only works if the run time types
are the same e.g.
------------
Dim o as Object = "Hello"
Dim i as Object = Cint(5)
Dim s as string = directcast(o, String) ' Will work, because o is a string
at runtime
Dim s1 as String = directcast(1, String) ' Won't work
------------
As for the other ways, they are more or less the same. In the examples you
gave, if you follow the IL generated, they you'll notice that all end up
calling the Int32.ToString() method.
See the other posts in this group relating to this issue:
"CType() versus Convert.ToXXXX()"
"DirectCast vc CType"
HTH,
Trev.
"Michael Ramey" <raterus@localhost> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
Hello,
There are quite a few ways to convert one object, say an integer to a
string.
Dim myStr as string
dim myInt as integer = 123
myStr = cstr(myInt)
myStr = myInt.toString()
myStr = CType(myInt, String)
or use DirectCast()
What is the preferred, fastest way? Any way I shouldn't be using because
it could be deprecated?
Thanks,
--Michael