开发者

Difference between converting strings [duplicate]

开发者 https://www.devze.com 2023-01-12 01:33 出处:网络
This question alread开发者_JAVA技巧y has answers here: Closed 12 years ago. Possible Duplicate: Difference between Convert.tostring() and .tostring()
This question alread开发者_JAVA技巧y has answers here: Closed 12 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消