Mega Code Archive

 
Categories / C# / Data Types
 

Converts Decimal to the equivalent 8-bit signed integer

using System; class MainClass {     public static void DecimalToS_Byte( decimal argument )     {         object SByteValue = null;         object ByteValue = null;         // Convert the argument to an sbyte value.         try         {             SByteValue = decimal.ToSByte( argument );         }         catch( Exception ex )         {             SByteValue = null;         }         // Convert the argument to a byte value.         try         {             ByteValue = decimal.ToByte( argument );         }         catch( Exception ex )         {             ByteValue = null;         }         Console.WriteLine( SByteValue);         Console.WriteLine( ByteValue );     }     public static void Main( )     {         DecimalToS_Byte( 8M );     } }