Sunday, January 6, 2013

convert.ToString() vs ToString() in C#


Lets understand the difference via this example:
int i= 0;
MessageBox.Show(i.ToString());
MessageBox.Show(Convert.ToString(i));
We can convert the integer i using i.ToString () or Convert.ToString. So what’s the difference?
The basic difference between them is the 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

No comments:

Post a Comment

Creating mirror of BST