Hemant Kumar
Hemant Kumar

Reputation: 4611

What is the basic difference between the ToString() and Convert.ToString()?

Can any help me in order to understand difference between convert.tostring() and tostring()?

Upvotes: 2

Views: 204

Answers (5)

Amit Kumawat
Amit Kumawat

Reputation: 602

If you use obj.ToString() and obj is null then here you will get an NullReferenceException. While if you are using Convert.ToString(obj) then it will not throw an exception if obj is null.

Upvotes: 0

Aman
Aman

Reputation: 79

ToString can not hold the Null value. Convert.ToString can hold the Null value

Upvotes: 0

if you invoke ToString() on null string it will throw NullReferenceException and Convert.ToString() does not throw NullReferenceException,instead you get empty string

Upvotes: 1

Sergey Mirvoda
Sergey Mirvoda

Reputation: 3239

It is huge. ToString() is method inherited from Object.
Convert.ToString is a method from IConvertible

Convert simply cast your object into IConvertible and calls appropriate method.

Upvotes: 1

jvanrhyn
jvanrhyn

Reputation: 2824

Have a look at this post By John Galloway

Upvotes: 2

Related Questions