C# Convert ToByte(UInt64)
Description
Convert ToByte(UInt64)
converts the value of the specified
64-bit unsigned integer to an equivalent 8-bit unsigned integer.
Syntax
Convert.ToByte(UInt64)
has the following syntax.
[CLSCompliantAttribute(false)]
public static byte ToByte(
ulong value
)
Parameters
Convert.ToByte(UInt64)
has the following parameters.
value
- The 64-bit unsigned integer to convert.
Returns
Convert.ToByte(UInt64)
method returns An 8-bit unsigned integer that is equivalent to value.
Example
The following example converts an array of unsigned long integers to Byte values.
/*from ww w.jav a 2s .c om*/
using System;
public class MainClass{
public static void Main(String[] argv){
ulong[] numbers= { UInt64.MinValue, 121, 340, UInt64.MaxValue };
byte result;
foreach (ulong number in numbers)
{
try {
result = Convert.ToByte(number);
Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
number.GetType().Name, number,
result.GetType().Name, result);
}
catch (OverflowException)
{
Console.WriteLine("The {0} value {1} is outside the range of the Byte type.",
number.GetType().Name, number);
}
}
}
}
The code above generates the following result.