Difference between Convert.toString and .toString() method.
To understand both the methods let's take an example:
int i =0;
MessageBox.Show(i.ToString());
MessageBox.Show(Convert.ToString(i));
Here both the methods are used to convert the string but 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.
Let's see another example:
string s;
object o = null;
s = o.ToString();
//returns a null reference exception for s.
string s;
object o = null;
s = Convert.ToString(o);
//returns an empty string for s and does not throw an exception.


Sunil jadhavPosted Mar 19, 2019, 5:35 AM EDT
Nice example.Clear to understand. Thanks for sharing...
Rajesh KumarPosted Dec 25, 2018, 7:52 AM EST
Nice article thanks for sharing...............