5

Possible Duplicate:
Difference between Convert.tostring() and .tostring()

Hi

Carrying on from this question What is the difference between Convert and Parse?

Here are two lines of code.

Convert.ToString(myObject);
myObject.ToString();

My question is what is the difference and which would be best to use?

Thank you in advance.

Community
  • 1
  • 1
Ash Burlaczenko
  • 24,778
  • 15
  • 68
  • 99

2 Answers2

4

The basic difference between them is Convert function handles NULLs while i.ToString() does not. It will throw a NULL reference exception error. So, as good coding practice using Convert is always safe.

Neil Knight
  • 47,437
  • 25
  • 129
  • 188
3

myObject.ToString() could throw a NullReferenceException, where Convert.ToString will never do that.

leppie
  • 115,091
  • 17
  • 196
  • 297