Difference between converting strings [duplicate]
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.
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.
myObject.ToString() could throw a NullReferenceException, where Convert.ToString will never do that.
加载中,请稍侯......
精彩评论