What is the difference between Convert.toString and .toString() method ?

Q

.NET INTERVIEW QUESTIONS - What is the difference between Convert.toString and .toString() method ?

✍: Guest

A

Consider this code.
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 “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.

2010-05-04, 4703👍, 0💬