C# BigInteger Explicit(BigInteger to Int16)

Description

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

Syntax

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


public static explicit operator short (
  BigInteger value
)

Parameters

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

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

Returns

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

Example


/* w  w  w  . j av a  2s  .c o  m*/

using System;
using System.IO;
using System.Numerics;

public class Example
{
   public static void Main()
   {
        BigInteger goodShort = 20000;
        BigInteger badShort = 33000;
        
        short shortFromBigInteger;
        
        // Successful conversion using cast operator. 
        shortFromBigInteger = (short) goodShort;
        Console.WriteLine(shortFromBigInteger);
        
        // Handle conversion that should result in overflow. 
        try
        {
           shortFromBigInteger = (short) badShort;
           Console.WriteLine(shortFromBigInteger);
        }
        catch (OverflowException e)
        {
           Console.WriteLine("Unable to convert {0}:\n   {1}", 
                             badShort, e.Message);
        }
          
   }
}
             

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Numerics »




BigInteger
Complex