Jay--
Which do YOU prefer?
Which do you recommend?
Please advise.
Thank you.
--Mark
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:u1**************@TK2MSFTNGP11.phx.gbl...
Mark,
If obj is type Object, why not just call obj.ToString()?
Convert.ToString is a framework function. Passing it an Object, causes it
to
use the IConvertable interface that the object implements, String
implements
this interface. I suspect it ultimately calls obj.ToString()
CType is a VB.NET keyword. It calls some internal VB.NET runtime functions.
I suspect it ultimately calls obj.ToString()
Don't forget there is also CStr, which is effectively shorthand for
CType(obj, String)
Also, for reference types (String is a reference type). if you know obj is
a
String, DirectCast is better.
The following articles may help:
Visual Basic .NET Internals
http://msdn.microsoft.com/library/de...tinternals.asp
Performance Optimization in Visual Basic .NET
http://msdn.microsoft.com/library/de...tchPerfOpt.asp
The first article has a section titled: Conversion Functions, CType,
DirectCast, and System.Convert that should address your question.
Hope this helps
Jay
"Mark Kamoski" <mk******@yahoo.com> wrote in message
news:Op**************@TK2MSFTNGP10.phx.gbl...
Hi--
What is the difference between Convert.ToString(obj) and CType(obj,
String)?
(Assume obj is a variable of type Object.)
Please advise.
Thank you.
--Mark