Converts the value of the current byte object to its equivalent string representation using the specified format.
The string representation of the current byte object, formatted as specified by the format parameter.
Type Reason FormatException format is invalid.
The format parameter can be either a standard or a custom numeric format string. All standard numeric format strings other than "R" (or "r") are supported, as are all custom numeric format characters. If format is null or an empty string (""), the return value is formatted with the general numeric format specifier ("G").
The return value of this function is formatted using the System.Globalization.NumberFormatInfo object for the thread current culture. For information about the thread current culture, see System.Threading.Thread.CurrentCulture. To provide formatting information for cultures other than the current culture, call the byte.ToString(string, IFormatProvider) method.
The .NET Framework provides extensive formatting support, which is described in greater detail in the following formatting topics:
For more information about numeric format specifiers, see Standard Numeric Format Strings and Custom Numeric Format Strings.
For more information about formatting, see Formatting Types.
The following example demonstrates the byte.ToString method.
C# Example
using System; public class ByteToStringExample { public static void Main() { Byte b = 8; Console.WriteLine(b); String[] formats = {"c", "d", "e", "f", "g", "n", "p", "x" }; foreach(String str in formats) Console.WriteLine("{0}: {1}", str, b.ToString(str)); } }
The output is
8