The major difference between convert.ToString() and ToString() is that,
convert.ToString() handles null but ToString() does not handles null.
Please see below two set of code:
This code will run successfully, no exception will be raised for that:
Below code will give an exception, unhandled Exception:NullReferenceException
convert.ToString() handles null but ToString() does not handles null.
Please see below two set of code:
This code will run successfully, no exception will be raised for that:
string name = null;
string abc = Convert.ToString(name);
Below code will give an exception, unhandled Exception:NullReferenceException
string name = null;string abc = name.ToString();
No comments:
Post a Comment