int. 64 c# code example
Example 1: Int64
ulong ulNumber = 163245617943825;
try {
long number1 = (long) ulNumber;
Console.WriteLine(number1);
}
catch (OverflowException) {
Console.WriteLine("{0} is out of range of an Int64.", ulNumber);
}
double dbl2 = 35901.997;
try {
long number2 = (long) dbl2;
Console.WriteLine(number2);
}
catch (OverflowException) {
Console.WriteLine("{0} is out of range of an Int64.", dbl2);
}
BigInteger bigNumber = (BigInteger) 1.63201978555e30;
try {
long number3 = (long) bigNumber;
Console.WriteLine(number3);
}
catch (OverflowException) {
Console.WriteLine("{0} is out of range of an Int64.", bigNumber);
}
Example 2: 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);
}
}