System.UInt64 Struct
Represents a 64-bit unsigned integer.
Syntax
public struct UInt64 : IComparable, IComparable<UInt64>, IConvertible, IEquatable<UInt64>, IFormattable
The UInt64 type is used when you need a non‑negative integer that requires more than 32 bits of storage. Its range is from 0 to 18,446,744,073,709,551,615 (2⁶⁴‑1).
Fields
| Name | Type | Description |
|---|---|---|
| MaxValue | ulong | Largest possible value of a UInt64. |
| MinValue | ulong | Smallest possible value of a UInt64. |
Methods
| Signature | Description |
|---|---|
static ulong Parse(string s) | Converts the string representation of a number to its UInt64 equivalent. |
static bool TryParse(string s, out ulong result) | Safely parses a string to a UInt64 without throwing an exception. |
string ToString() | Returns the string representation of the current value. |
string ToString(string format) | Formats the value using the specified format string. |
int CompareTo(object value) | Compares this instance to a specified object. |
int CompareTo(ulong value) | Compares this instance to a specified UInt64 value. |
bool Equals(ulong obj) | Determines whether this instance is equal to another UInt64 value. |
ulong GetHashCode() | Returns a hash code for this instance. |
TypeCode GetTypeCode() | Gets the TypeCode for this instance. |
Operators
| Operator | Description |
|---|---|
+ | Addition. |
- | Subtraction. |
* | Multiplication. |
/ | Division. |
% | Remainder. |
== | Equality. |
!= | Inequality. |
< | Less than. |
> | Greater than. |
<= | Less than or equal. |
>= | Greater than or equal. |
Example: Parsing and Formatting
using System;
class Program
{
static void Main()
{
string s = "18446744073709551615";
if (UInt64.TryParse(s, out ulong value))
{
Console.WriteLine($\"Parsed value: {value:N0}\");
Console.WriteLine($\"Hex: {value:X}\");
}
else
{
Console.WriteLine(\"Unable to parse the string.\");
}
}
}
Output:
Parsed value: 18,446,744,073,709,551,615 Hex: FFFFFFFFFFFFFFFF