C# BigInteger Explicit(BigInteger to UInt64)

Description

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

Syntax

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


public static explicit operator ulong (
  BigInteger value
)

Parameters

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

  • value - The value to convert to an unsigned 64-bit integer.

Returns

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

Example


/*from   www . j a v  a  2 s  .c  o  m*/
using System;
using System.IO;
using System.Numerics;

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

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Numerics »




BigInteger
Complex