You can declare and initialize a long variable like this example:
When an integer literal has no suffix, its type is the first of these types in which its value can be represented: int, uint, long, ulong. In the preceding example, it is of the type long because it exceeds the range of uint (see Integral Types Table (C# Reference) for the storage sizes of integral types).
You can also use the suffix L with the long type like this:
long long2 = 4294967296L;
When you use the suffix L, the type of the literal integer is determined to be either long or ulong according to its size. In the case it is long because it less than the range of ulong.
A common use of the suffix is with calling overloaded methods. Consider, for example, the following overloaded methods that use long and int parameters:
public static void SampleMethod(int i) {}
public static void SampleMethod(long l) {}
Using the suffix L guarantees that the correct type is called, for example:
SampleMethod(5); // Calling the method with the int parameter
SampleMethod(5L); // Calling the method with the long parameter
You can use the long type with other numeric integral types in the same expression, in which case the expression is evaluated as long (or bool in the case of relational or Boolean expressions). For example, the following expression evaluates as long:
Note |
|---|
| You can also use the lowercase letter "l" as a suffix. However, this generates a compiler warning because the letter "l" is easily confused with the digit "1." Use "L" for clarity. |
For information on arithmetic expressions with mixed floating-point types and integral types, see float and double.