C# BigInteger Explicit(BigInteger to Int64)

Description

BigInteger Explicit(BigInteger to Int64) Defines an explicit conversion of a BigInteger object to a 64-bit signed integer value.

Syntax

BigInteger.Explicit(BigInteger to Int64) has the following syntax.


public static explicit operator long (
  BigInteger value
)

Parameters

BigInteger.Explicit(BigInteger to Int64) has the following parameters.

  • value - The value to convert to a 64-bit signed integer.

Returns

BigInteger.Explicit(BigInteger to Int64) method returns An object that contains the value of the value parameter.

Example


/*w  ww.  jav  a2s .  c o m*/
using System;
using System.IO;
using System.Numerics;

public class Example
{
   public static void Main()
   {
        // BigInteger to Int64 conversion.
        BigInteger goodLong = 2000000000;
        BigInteger badLong = BigInteger.Pow(goodLong, 3);
        
        long longFromBigInteger;
        
        // Successful conversion using cast operator. 
        longFromBigInteger = (long) goodLong;
        Console.WriteLine(longFromBigInteger);
        
        // Handle conversion that should result in overflow. 
        try
        {
           longFromBigInteger = (long) badLong;
           Console.WriteLine(longFromBigInteger);
        }
        catch (OverflowException e)
        {
           Console.WriteLine("Unable to convert {0}:\n   {1}", 
                             badLong, e.Message);
        }
            
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Numerics »




BigInteger
Complex