Byte.ToString Method (String)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Function ToString ( _
    format As String _
) As String
[SecuritySafeCriticalAttribute]
public string ToString(
    string format
)

Parameters

Return Value

Type: System.String
The string representation of the current Byte object, formatted as specified by the format parameter.

Exceptions

Exception Condition
FormatException

format includes an unsupported specifier. Supported format specifiers are listed in the Remarks section.

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 nulla null reference (Nothing in Visual Basic) 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 NumberFormatInfo object for the thread current culture. For information about the thread current culture, see 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:

Examples

The following example initializes a Byte value and displays it to the console using each of the supported standard format strings and a custom format string. The example is run with en-US as the current culture.

Dim formats() As String = {"C3", "D4", "e1", "E2", "F1", "G", _
                           "N1", "P0", "X4", "0000.0000"}
Dim number As Byte = 240
For Each format As String In formats
   outputBlock.Text &= String.Format("'{0}' format specifier: {1}", _
                     format, number.ToString(format)) & vbCrLf
Next
' The example displays the following output if the
' current culture is en-us:
'       'C3' format specifier: $240.000
'       'D4' format specifier: 0240
'       'e1' format specifier: 2.4e+002
'       'E2' format specifier: 2.40E+002
'       'F1' format specifier: 240.0       
'       'G' format specifier: 240
'       'N1' format specifier: 240.0
'       'P0' format specifier: 24,000 %
'       'X4' format specifier: 00F0
'       '0000.0000' format specifier: 0240.0000           
string[] formats = {"C3", "D4", "e1", "E2", "F1", "G", "N1", 
                    "P0", "X4", "0000.0000"};
byte number = 240;
foreach (string format in formats)
   outputBlock.Text += String.Format("'{0}' format specifier: {1}",
                     format, number.ToString(format)) + "\n";

// The example displays the following output if the
// current culture is en-us:
//       'C3' format specifier: $240.000
//       'D4' format specifier: 0240
//       'e1' format specifier: 2.4e+002
//       'E2' format specifier: 2.40E+002
//       'F1' format specifier: 240.0
//       'G' format specifier: 240
//       'N1' format specifier: 240.0
//       'P0' format specifier: 24,000 %
//       'X4' format specifier: 00F0
//       '0000.0000' format specifier: 0240.0000           

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.