Defines an explicit conversion of a BigInteger object to an unsigned byte value.
using System;
using System.Numerics;
public class Example
{
public static void Main()
{
BigInteger goodByte = BigInteger.One;
BigInteger badByte = 256;
byte byteFromBigInteger;
byteFromBigInteger = (byte) goodByte;
Console.WriteLine(byteFromBigInteger);
try
{
byteFromBigInteger = (byte) badByte;
Console.WriteLine(byteFromBigInteger);
}
catch (OverflowException e)
{
Console.WriteLine("Unable to convert {0}:\n {1}",
badByte, e.Message);
}
}
}
Related examples in the same category