Google+ Followers

Monday, June 17, 2013

C#,Vb.Net - Difference between Convert.tostring(Object) and Object.tostring() method Example


In this Post I will explain you differences between obj.tostring() and Convert.tostring(obj) in

Explanation :

The basic difference between them is “Convert.ToString(Object)” handles NULL values even if variable value become null but “Object.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 an empty string for str and does not throw an exception. string str; object i = null; str = Convert.ToString(i); Returns a null reference exception for str. string str; object i = null; str = i.ToString();

1 comment:

  1. Convert your VB programs to C# with over 99% accuracy with the VBConversions VB.Net to C# Converter, the most accurate VB.Net to C# Converter available. Free download available at

    convert to c#