Infolink

 

Search This Blog

Oct 3, 2012

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:

    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

Related Posts Plugin for WordPress, Blogger...