Convert.ToInt16 Method (Byte)

 

Converts the value of the specified 8-bit unsigned integer to the equivalent 16-bit signed integer.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public static short ToInt16(
	byte value
)

Parameters

value
Type: System.Byte

The 8-bit unsigned integer to convert.

Return Value

Type: System.Int16

A 16-bit signed integer that is equivalent to value.

The following example converts each element in an array of Byte values to a 16-bit signed integer.

byte[] bytes = { Byte.MinValue, 14, 122, Byte.MaxValue};
short result;

foreach (byte byteValue in bytes)
{
   result = Convert.ToInt16(byteValue);
   Console.WriteLine("The Byte value {0} converts to {1}.",
                     byteValue, result);
}
// The example displays the following output:
//       The Byte value 0 converts to 0.
//       The Byte value 14 converts to 14.
//       The Byte value 122 converts to 122.
//       The Byte value 255 converts to 255.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: