Convert.tostring vs obj.tostring

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi,

I was wondering whether a difference existed between the Convert.ToString() method and the method ToString() that is sometimes available in some classes. Is one method preferred over another?

Thanks.
Mike
 
Hi Mike,

From what I know, Convert.ToString attempts to cast the argument to
IConvertible first and then to invoke ToString on the IConvertible. If this
attempt fails, then Convert.ToString invokes the ToString() method directly
on the argument. This is at least true for the overload accepting the
argument of type Object. For overloads accepting arguments of known types
such as Byte, there is no difference between Convert.ToString and the
ToString() method.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx


Hi,

I was wondering whether a difference existed between the Convert.ToString()
method and the method ToString() that is sometimes available in some
classes. Is one method preferred over another?

Thanks.
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top