In C#, Convert.ToUInt64 returns a ulong—unsigned 64-bit integer from 0 to 18,446,744,073,709,551,615.
Use it for very large counters and IDs that never go negative.
This is a static member of System.Convert. You call it with the type name, such as Convert.ToUInt64(...). Convert is the everyday API for converting between common CLR types in C#.
Syntax
Convert text or numbers into a ulong.
C#
ulong a = Convert.ToUInt64("10000000000");
ulong b = Convert.ToUInt64(42);
ulong c = Convert.ToUInt64("FF", 16);
Call
What it does
Convert.ToUInt64("10000000000")
Large digit string → ulong.
Convert.ToUInt64("FF", 16)
Hex with base 16.
null → 0. Negatives overflow. Prefer ulong.TryParse for soft failure.
Library declarations
C#
public static ulong ToUInt64(string? value);
public static ulong ToUInt64(string? value, int fromBase);
public static ulong ToUInt64(long value);
Parameters
Parameter
Description
value
Required. Text or number to convert.
fromBase
Optional. 2, 8, 10, or 16.
Return Value
Return Value
Description
ulong
Unsigned 64-bit result.
C# Examples
Example 1 — Ten Billion as ULong
Parse a value beyond signed 32-bit range.
C#
using System;
class Program {
static void Main() {
ulong n = Convert.ToUInt64("10000000000");
Console.WriteLine(n);
Console.WriteLine(n + 5);
}
}
Output
10000000000
10000000005
How It Works
10 billion. Needs a wide integer type.
ulong holds it. Unsigned 64-bit succeeds.
Add five. Counter-style math works.
Non-negative. Ideal for sizes and ticks.
Example 2 — Hex to ULong
Parse hex digits into ulong.
C#
using System;
class Program {
static void Main() {
ulong n = Convert.ToUInt64("1F4", 16);
Console.WriteLine(n);
Console.WriteLine(Convert.ToUInt64("100", 2));
}
}
Output
500
4
How It Works
1F4 hex. Equals decimal 500.
Binary 100. Equals 4.
fromBase. Same pattern as other Convert methods.
Result ulong. Even small values use UInt64 here.
Example 3 — Reject Signed Negatives
Catch OverflowException for −1.
C#
using System;
class Program {
static void Main() {
try {
Console.WriteLine(Convert.ToUInt64(-1));
} catch (OverflowException) {
Console.WriteLine("unsigned only");
}
Console.WriteLine(Convert.ToUInt64(0));
}
}
Output
unsigned only
0
How It Works
−1 overflows. ulong cannot store negatives.
Handle it. Catch and explain.
Zero works. Minimum unsigned value.
Use ToInt64. When you need signed magnitude.
Frequently Asked Questions
For very large non-negative integers beyond uint/long needs.