The following example describes the difference.
int i =0;
MessageBox.Show(i.ToString());
MessageBox.Show(Convert.ToString(i));
We can convert the integer “i” using “i.ToString()” or “Convert.ToString”.
The basic difference between “i.ToString()” and “Convert.ToString” is “Convert” function handles NULLS while “i.ToString()” does not and it will throw a NULL reference exception error. Hence the good coding practice is using “convert” which is always safe.
Sunday, August 16, 2009
Difference between Convert.ToString and .ToString()
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment