C# Convert ToString() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Convert

Definition

In C#, Convert.ToString builds a string from many value types and objects.

It is handy when you have an object that might be null—Convert.ToString(null) returns null instead of throwing, unlike calling .ToString() on a null reference.

This is a static member of System.Convert. You call it with the type name, such as Convert.ToString(...). Convert is the everyday API for converting between common CLR types in C#.

Syntax

Pass any common value (and optionally a format provider or base).

C#
string a = Convert.ToString(99);
string b = Convert.ToString(true);
string c = Convert.ToString(255, 16);  // "ff"
CallWhat it does
Convert.ToString(99)Number → decimal text.
Convert.ToString(true)Bool → "True".
Convert.ToString(255, 16)Int with base 16 → hex text.

Convert.ToString(null) returns null. Base overloads on integers produce binary/octal/hex text.

Library declarations
C#
public static string? ToString(object? value);
public static string ToString(int value);
public static string ToString(int value, int toBase);

Parameters

ParameterDescription
valueRequired. Value to turn into text.
toBaseOptional for integers. 2, 8, 10, or 16.

Return Value

Return ValueDescription
stringText form of the value (may be null for null object input).

C# Examples

Example 1 — Everyday ToString Calls

Convert ints and bools to display text.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine(Convert.ToString(99));
        Console.WriteLine(Convert.ToString(true));
        Console.WriteLine(Convert.ToString(3.5));
    }
}

How It Works

  1. Int text. 99 becomes "99".
  2. Bool spelling. true prints as True.
  3. Double text. 3.5 becomes culture-aware digits.
  4. Ready to log. Results are strings for output.

Example 2 — Integer to Hex String

Use toBase 16 to print hex digits.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine(Convert.ToString(255, 16));
        Console.WriteLine(Convert.ToString(8, 2));
        Console.WriteLine(Convert.ToString(64, 8));
    }
}

How It Works

  1. Hex 255. Base 16 yields ff.
  2. Binary 8. Base 2 yields 1000.
  3. Octal 64. Base 8 yields 100.
  4. Lowercase hex. Letters appear in lowercase.

Example 3 — Null Does Not Throw

Compare Convert.ToString(null) with a real value.

C#
using System;

class Program {
    static void Main() {
        string? missing = Convert.ToString(null);
        string present = Convert.ToString(42);
        Console.WriteLine(missing == null);
        Console.WriteLine(present);
    }
}

How It Works

  1. Null in. Convert returns a null string reference.
  2. Check equality. missing == null is true.
  3. Present value. 42 becomes "42".
  4. Safer than instance. obj.ToString() would throw if obj is null.

Frequently Asked Questions

null (no exception).
Convert.ToString(255, 16) returns "ff".
Similar for non-null values; Convert is safer when the object may be null.
Yes for floating-point and some formatted conversions.
Yes—Convert.ToString(date) uses culture formatting.

Next: ToUInt16()

Convert a value to ushort (0…65535) with System.Convert.

ToUInt16() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful