Mega Code Archive

 
Categories / C# / Data Types
 

Converts Decimal to the equivalent 32-bit signed integer

using System; class MainClass {     public static void DecimalToU_Int32( decimal argument )     {         object Int32Value = null;         object UInt32Value = null;         // Convert the argument to an int value.         try         {             Int32Value = decimal.ToInt32( argument );         }         catch( Exception ex )         {             Int32Value = null;         }         // Convert the argument to a uint value.         try         {             UInt32Value = decimal.ToUInt32( argument );         }         catch( Exception ex )         {             UInt32Value = null;         }         Console.WriteLine( Int32Value );         Console.WriteLine( UInt32Value );     }     public static void Main( )     {         DecimalToU_Int32( 123M );     } }