In
this article I will explain differences between .tostring() and Convert.tostring()
in asp.net.
The
basic difference between them is “Convert.ToString(variable)”
handles NULL values even if variable value become null but “variable.ToString()” will not handle NULL
values it will throw a NULL reference exception error. So as a good coding practice
using “convert” is always safe.
A Small Example as follws
//Returns a null reference
exception for str.
string string1;
object s1i = null;
string1= i1.ToString();
//Returns an empty string for str
and does not throw an exception. If you dont
string string2;
object i = null;
string2= Convert.ToString(i);
Comments
Post a Comment