We can't assign NULL to int.
int i = 0;
Convert.ToString() method is preferable to use over the implicit .ToString()
The behavior of the ToString() method can vary wildly depending on the type of object
The problem is that the ToString() method requires a valid instance of the object. If you intend to use the ToString() method, you should be testing that the object isn't null
Response.Write(i.ToString());
Response.Write("
" + Convert.ToString(i));
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.
int i = 0;
Convert.ToString() method is preferable to use over the implicit .ToString()
The behavior of the ToString() method can vary wildly depending on the type of object
The problem is that the ToString() method requires a valid instance of the object. If you intend to use the ToString() method, you should be testing that the object isn't null
Response.Write(i.ToString());
Response.Write("
" + Convert.ToString(i));
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.