Convert to string methods

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Sometime I can use:
Value.ToString()
but sometimes the compiler gives an error to this and I must use:
Convert.ToString(Value)

Can someone explain me the difference, and when to use which of the 2
methods ?
 
Hi,

I think they are identical . The class Convert only calls the ToString ()
method of an object. If the object has a ToString () method then I would use
the ToString .. for more complex conversions I would use Convert class.
 
Hi,

Sometime I can use:
Value.ToString()
but sometimes the compiler gives an error to this and I must use:
Convert.ToString(Value)

Can someone explain me the difference, and when to use which of the 2
methods ?

If value is an object then the difference is that value.ToString will throw
an exception of the object is null whereas Convert.ToString(value) will
return an empty string.
 
Back
Top