C# BigInteger Explicit(BigInteger to Int32)
Description
BigInteger Explicit(BigInteger to Int32)
Defines an
explicit conversion of a BigInteger object to a 32-bit signed integer value.
Syntax
BigInteger.Explicit(BigInteger to Int32)
has the following syntax.
public static explicit operator int (
BigInteger value
)
Parameters
BigInteger.Explicit(BigInteger to Int32)
has the following parameters.
value
- The value to convert to a 32-bit signed integer.
Returns
BigInteger.Explicit(BigInteger to Int32)
method returns An object that contains the value of the value parameter.
Example
//from w w w.j a v a 2 s .co m
using System;
using System.IO;
using System.Numerics;
public class Example
{
public static void Main()
{
BigInteger goodInteger = 200000;
BigInteger badInteger = 123123123123;
int integerFromBigInteger;
integerFromBigInteger = (int) goodInteger;
Console.WriteLine(integerFromBigInteger);
try
{
integerFromBigInteger = (int) badInteger;
Console.WriteLine(integerFromBigInteger);
}
catch (OverflowException e)
{
Console.WriteLine("Unable to convert {0}:\n {1}",
badInteger, e.Message);
}
}
}
The code above generates the following result.