Convert Decimal to short in CSharp
Description
The following code shows how to convert Decimal to short.
Example
using System;// w w w . j a va 2 s . c o m
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 );
}
}
The code above generates the following result.