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"
Call
What 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
Parameter
Description
value
Required. Value to turn into text.
toBase
Optional for integers. 2, 8, 10, or 16.
Return Value
Return Value
Description
string
Text 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));
}
}
Output
99
True
3.5
How It Works
Int text. 99 becomes "99".
Bool spelling. true prints as True.
Double text. 3.5 becomes culture-aware digits.
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));
}
}
Output
ff
1000
100
How It Works
Hex 255. Base 16 yields ff.
Binary 8. Base 2 yields 1000.
Octal 64. Base 8 yields 100.
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);
}
}
Output
True
42
How It Works
Null in. Convert returns a null string reference.
Check equality.missing == null is true.
Present value. 42 becomes "42".
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.