System.Byte.ToString Method

Converts the value of the current byte object to its equivalent string representation using the specified format.

Syntax

public string ToString (string format)

Parameters

format
A numeric format string.

Returns

The string representation of the current byte object, formatted as specified by the format parameter.

Exceptions

TypeReason
FormatException format is invalid.

Remarks

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:

Example

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
c: $8.00
d: 8
e: 8.000000e+000
f: 8.00
g: 8
n: 8.00
p: 800.00 %
x: 8

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0