In C#, Convert.ToInt64 returns a long (64-bit signed integer) from text or other numbers.
Use it when values may exceed the 32-bit int range. Base overloads parse binary, octal, or hex strings.
This is a static member of System.Convert. You call it with the type name, such as Convert.ToInt64(...). Convert is the everyday API for converting between common CLR types in C#.
Syntax
Convert text or numbers into a long.
C#
long a = Convert.ToInt64("3000000000");
long b = Convert.ToInt64(42);
long c = Convert.ToInt64("1A", 16);
Call
What it does
Convert.ToInt64("3000000000")
Large digit string → long.
Convert.ToInt64("1A", 16)
Hex with base 16.
null → 0. Prefer long.TryParse for untrusted text.
Library declarations
C#
public static long ToInt64(string? value);
public static long ToInt64(string? value, int fromBase);
public static long ToInt64(int value);
Parameters
Parameter
Description
value
Required. Text or number to convert.
fromBase
Optional. 2, 8, 10, or 16.
Return Value
Return Value
Description
long
64-bit signed result.
C# Examples
Example 1 — Beyond Int32 Range
Parse a value too big for a 32-bit int.
C#
using System;
class Program {
static void Main() {
long n = Convert.ToInt64("3000000000");
Console.WriteLine(n);
Console.WriteLine(n + 1);
}
}
Output
3000000000
3000000001
How It Works
3 billion. Larger than Int32.MaxValue.
long fits. ToInt64 stores it safely.
Increment. Adding 1 shows ordinary math.
Choose width. Use Int64 when int is too small.
Example 2 — Binary String to Long
Parse a binary digit string.
C#
using System;
class Program {
static void Main() {
long n = Convert.ToInt64("11111111", 2);
Console.WriteLine(n);
Console.WriteLine(Convert.ToInt64("FF", 16));
}
}
Output
255
255
How It Works
Eight ones. Binary 11111111 equals 255.
Hex FF. Same magnitude from base 16.
fromBase. Selects how digits are read.
Result is long. Even small values use Int64 here.
Example 3 — Null Becomes Zero
Show Convert null behavior for ToInt64.
C#
using System;
class Program {
static void Main() {
Console.WriteLine(Convert.ToInt64(null));
Console.WriteLine(Convert.ToInt64("0"));
Console.WriteLine(Convert.ToInt64("-7"));
}
}
Output
0
0
-7
How It Works
Null path. Convert returns 0 instead of throwing.
Zero text."0" also yields 0.
Negatives. Leading minus works for decimal strings.