Type Range Default Value
long -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 0

The long type represents a 64-bit signed two's-complement integer. The long type can also use the alias signed long.


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 long type is L. 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 as a suffix for long.


The 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 long type is necessary; for example, it can be necessary for compatibility with SQL datatypes which also provide 64-bit signed two's-complement integers.


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

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 100L is interpreted as long and can be assigned to a variable of type System.Integer64 via auto-boxing:

System.Integer64 value = 100L; // Auto-boxing

Without auto-boxing, the equivalent code would be:

System.Integer64 value = new System.Integer64(100L);

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

long value = new System.Integer64(100L); // 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 long type, and, at runtime, the variable's value exceeds the long maximum (9,223,372,036,854,775,807) by one, it will wrap around to the long minimum (-9,223,372,036,854,775,808); if the value exceeds the long maximum by two, it will wrap around to the long minimum plus one (-9,223,372,036,854,775,807); and so on.


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

See Also


HTML | BBCode | Direct Link