Mega Code Archive

 
Categories / C# / Data Types
 

Converts Decimal to the 16-bit unsigned integer

using System; class MainClass {     public static void DecimalToU_Int16( decimal argument )     {         object Int16Value = null;         object UInt16Value = null;         // Convert the argument to a short value.         try         {             Int16Value = decimal.ToInt16( argument );         }         catch( Exception ex )         {             Int16Value = null;         }         // Convert the argument to a ushort value.         try         {             UInt16Value = decimal.ToUInt16( argument );         }         catch( Exception ex )         {             UInt16Value = null;         }         Console.WriteLine( Int16Value);          Console.WriteLine(  UInt16Value );     }     public static void Main( )     {         DecimalToU_Int16( 123M );     } }