C# – Difference between Convert.ToString and .ToString() method

In this post i will show you what is the main difference between Convert.ToString and .ToString() method.

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.

//Returns a null reference exception for Name.
string Name;
object i = null;
Name= i.ToString();

//Returns an empty string for name and does not throw an exception.
string Name;
object i = null;
Name = Convert.ToString(i);
0 0 votes
Article Rating

Do you want to hire us for your Project Work? Then Contact US.
Spread the love
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x