Convert Decimal to byte in CSharp
Description
The following code shows how to convert Decimal to byte.
Example
//from ww w . j ava2s .c om
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 );
}
}
The code above generates the following result.