Convert.ToString Method (Byte)

July 28, 2014

Converts the value of the specified 8-bit unsigned integer to its equivalent String representation.

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

public static string ToString(
	byte value
)

Parameters

value
Type: System.Byte
An 8-bit unsigned integer.

Return Value

Type: System.String
The String equivalent of the value of value.

This implementation is identical to Byte.ToString.

The following code sample illustrates the conversion of a Byte to a String, using ToString.


public void ConvertStringByte(string stringVal)
{
   byte byteVal = 0;

   try
   {
      byteVal = System.Convert.ToByte(stringVal);
      outputBlock.Text += String.Format("{0} as a byte is: {1}",
         stringVal, byteVal) + "\n";
   }
   catch (System.OverflowException)
   {
      outputBlock.Text += String.Format(
         "Conversion from string to byte overflowed.") + "\n";
   }
   catch (System.FormatException)
   {
      outputBlock.Text += String.Format(
         "The string is not formatted as a byte.") + "\n";
   }
   catch (System.ArgumentNullException)
   {
      outputBlock.Text += String.Format(
         "The string is null.") + "\n";
   }

   //The conversion from byte to string is always valid.
   stringVal = System.Convert.ToString(byteVal);
   outputBlock.Text += String.Format("{0} as a string is {1}",
      byteVal, stringVal) + "\n";
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft