Diff b/w Convert.toString and .toString()


The Difference between Convert.toString and .toString()

Hi,


int m =0;
MessageBox.Show(m.ToString());
MessageBox.Show(Convert.ToString(m));



The basic difference between them is "Convert" function handles NULLS while
"m.ToString()" does not it will throw a NULL reference exception error. So as a good coding
practice using "convert" is always safe.


Comments

Author: Narayana23 Jun 2010 Member Level: Gold   Points : 1


Hi,

Thanks for giving such a good tip really it helps me a lot while writing in coding and also avoid showing exception.

Regards
Narayana

Author: Santosh Kumar Singh23 Jun 2010 Member Level: Gold   Points : 1

Hi,

ToString() raise exception when the object is null

Convert.ToString() return string.Empty in case of null object



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: