Reputation: 4611
Can any help me in order to understand difference between convert.tostring() and tostring()?
Upvotes: 2
Views: 204
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
Reputation: 79
ToString can not hold the Null value. Convert.ToString can hold the Null value
Upvotes: 0
Reputation: 11155
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
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