unsigned long

Type Range Default Value
unsigned long 0 to 18,446,744,073,709,551,615 0

The unsigned long type represents a 64-bit unsigned two's-complement integer.


Integrals without a suffix are interpreted in this order: int, unsigned int, long, unsigned long, byte, signed byte, short, unsigned short, and char. If the integral value does not "fit" within any specified types, such as possible function overloads or a specified variable type, an error will be raised at compile time.

The suffix for the unsigned long type is UL. To avoid confusion with some fonts where the number 1 (one) and the lowercase "L" ("l") are indistinguishable, the lowercase "L" ("l") cannot be used in the suffix for long. Likewise, for consistency, the suffix for unsigned long must also be uppercase.


The unsigned long type is emulated in JS++ if JavaScript is the compilation target. This can be a source for performance slowdowns, and this type should therefore be used sparingly. Nevertheless, the unsigned long type is necessary; for example, it can be necessary for compatibility with SQL datatypes which also provide 64-bit unsigned two's-complement integers.


All primitive types have a corresponding wrapper class. The corresponding wrapper class for the unsigned long type is System.UInteger64.

Auto-boxing occurs when a value of a primitive type is assigned or passed as an argument to a variable or function that expects a value of its corresponding wrapper class. For example, the integer literal 100UL is interpreted as unsigned long and can be assigned to a variable of type System.UInteger64 via auto-boxing:

System.UInteger64 value = 100UL; // Auto-boxing

Without auto-boxing, the equivalent code would be:

System.UInteger64 value = new System.UInteger64(100UL);

The reverse also occurs. Unboxing is when the wrapper class is automatically converted to its corresponding primitive type. Thus, an instance of System.UInteger64 can be unboxed to the unsigned long primitive type.

unsigned long value = new System.UInteger64(100UL); // Unboxing

Overflow and Wrapping

When values for integer types go out of range at runtime, they will "wrap around". Thus, if a variable is declared as having the unsigned long type, and, at runtime, the variable's value exceeds the unsigned long maximum (18,446,744,073,709,551,615) by one, it will wrap around to the unsigned long minimum (0); if the value exceeds the unsigned long maximum by two, it will wrap around to the unsigned long minimum plus one (1); and so on.


For conversions to and from the unsigned long type, consult the Conversions Table.

See Also


HTML | BBCode | Direct Link