Share via


SByte.ToString Method (String, IFormatProvider)

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

Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.

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

Syntax

'Declaration
Public Function ToString ( _
    format As String, _
    provider As IFormatProvider _
) As String
public string ToString(
    string format,
    IFormatProvider provider
)

Parameters

  • format
    Type: System.String
    A standard or custom numeric format string.

Return Value

Type: System.String
The string representation of the value of this instance as specified by format and provider.

Implements

IFormattable.ToString(String, IFormatProvider)

Exceptions

Exception Condition
FormatException

format is invalid.

Remarks

The format parameter can be any valid standard numeric format specifier, or any combination of custom numeric format specifiers. If format is equal to String.Empty or is nulla null reference (Nothing in Visual Basic), the return value of the current SByte object is formatted with the general format specifier ("G"). If format is any other value, the method throws a FormatException.

The .NET Framework provides extensive formatting support, which is described in greater detail in the following formatting topics:

The provider parameter is an IFormatProvider implementation. Its GetFormat method returns a NumberFormatInfo object that provides culture-specific information about the format of the string returned by this method. When the ToString(String, IFormatProvider) method is invoked, it calls the provider parameter's IFormatProvider.GetFormat method and passes it a Type object that represents the NumberFormatInfo type. The GetFormat method then returns the NumberFormatInfo object that provides information for formatting the value parameter, such as the negative sign symbol, the group separator symbol, or the decimal point symbol. There are three ways to use the provider parameter to supply formatting information to the ToString(String, IFormatProvider) method:

  • You can pass a CultureInfo object that represents the culture that supplies formatting information. Its GetFormat method returns the NumberFormatInfo object that provides numeric formatting information for that culture.

  • You can pass the actual NumberFormatInfo object that provides numeric formatting information. (Its implementation of GetFormat just returns itself.)

  • You can pass a custom object that implements IFormatProvider. Its GetFormat method instantiates and returns the NumberFormatInfo object that provides formatting information.

If provider is nulla null reference (Nothing in Visual Basic), the formatting of the returned string is based on the NumberFormatInfo object of the current culture.

Examples

The following example displays both a positive and a negative SByte value using the standard numeric format specifiers and a number of specific CultureInfo objects.

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.