DEV Community

The DotNET Weekly
The DotNET Weekly

Posted on


What are the differences between Convert.ToString() and .ToString() method?

The basic difference between the 2 methods is

  • Convert.ToString() can handle NULL
  • .ToString() does not handle NULL

Let's test this out. In the below code snippet, we have a string object which is set to a value of NULL.

Code Snippet

class Program
    public static void Main()
        string name = null;
        Console.WriteLine("Convert.ToString output is = " + Convert.ToString(name));
        Console.WriteLine(".ToString output is = " + name.ToString());


Convert.ToString output is =

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
   at test.console.Program.Main() in C:\DevTo\ToString\Program.cs:line 14

The .ToString() method cannot handle NULLs and throws a NullReferenceException.

Let me know in the comments what do you use between these two :)

Follow me on for more such posts.

Top comments (2)

sirseanofloxley profile image
Sean Allin Newell

Convert.ToString certainly handles null elegantly, but we can control null coalescence with the instance method too.

aStr?.ToString() ?? "";
thedotnetweekly profile image
The DotNET Weekly • Edited

That is true Sean.Unfortunately, the most common mistake I have seen people do is even after being aware of this and forget to put it until an exception is thrown on production :)

Speaking tips for shy people

How to speak at conferences when you’re scared of public speaking

In 2022, I did something I never thought I would do – stand on a stage and speak to a large audience. Most notably, I delivered part of the keynote at GitHub Universe, GitHub's annual conference.