int64 code example
Example 1: Int64
decimal[] values= { Decimal.MinValue, -1034.23m, -12m, 0m, 147m,
199.55m, 9214.16m, Decimal.MaxValue };
long result;
foreach (decimal value in values)
{
try {
result = Convert.ToInt64(value);
Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.",
value.GetType().Name, value,
result.GetType().Name, result);
}
catch (OverflowException) {
Console.WriteLine("{0} is outside the range of the Int64 type.",
value);
}
}
// The example displays the following output:
// -79228162514264337593543950335 is outside the range of the Int64 type.
// Converted the Decimal value '-1034.23' to the Int64 value -1034.
// Converted the Decimal value '-12' to the Int64 value -12.
// Converted the Decimal value '0' to the Int64 value 0.
// Converted the Decimal value '147' to the Int64 value 147.
// Converted the Decimal value '199.55' to the Int64 value 200.
// Converted the Decimal value '9214.16' to the Int64 value 9214.
// 79228162514264337593543950335 is outside the range of the Int64 type.
Example 2: Int64
sbyte value1 = 124;
short value2 = 1618;
int value3 = Int32.MaxValue;
long number1 = value1;
long number2 = value2;
long number3 = value3;