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
  • 23,106
  • 15
  • 65
  • 96

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
  • 45,890
  • 23
  • 126
  • 186
3

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

leppie
  • 112,162
  • 17
  • 191
  • 293