- value
- The 64-bit unsigned integer value to be converted.
value as a byte.
Type Reason OverflowException value is greater than byte.MaxValue.
This member is not CLS-compliant. For a CLS-compliant alternative, use Convert.ToByte(object)(decimal).
The following example demonstrates converting ulong values to byte values.
C# Example
using System; class ConvertByteTest { static public void Main() { ulong ulong0 = 0; ulong ulong1 = 32000; byte byte0 = Convert.ToByte(ulong0); Console.WriteLine("(ulong) {0} as byte = {1}",ulong0,byte0); byte byte1 = Convert.ToByte(ulong1); //Throws an exception. Console.WriteLine("(ulong) {0} as byte = {1}",ulong1,byte1); } }The output is
(ulong) 0 as byte = 0
Exception occurred: System.OverflowException: Value was either too large or too small for an unsigned byte.
at Convert.ToByte(UInt64 value)
at ConvertByteTest.Main() in C:\ECMAExamples\ConvertToByte\ConvertUInt64.cs:line 8
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0