Convert sbyte to byte

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I convert an sbyte to a byte. When I try the code
below, it blows up if the sbyte is a negative number.

sbyte[] sbytes = input;

for( int i = 0; i < sbytes.Length; i++ )
{
byte x = Convert.ToByte( sbytes );
Console.WriteLine( x );
}
 
How do I convert an sbyte to a byte. When I try the code
below, it blows up if the sbyte is a negative number.

sbyte[] sbytes = input;

for( int i = 0; i < sbytes.Length; i++ )
{
byte x = Convert.ToByte( sbytes );
Console.WriteLine( x );
}


Rather than using Convert.ToByte, just cast the sbyte to a byte. That
will work so long as you don't have overflow checking turned on.
 
Back
Top