System.UInt16.ToString Method

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

Syntax

public string ToString (string format, IFormatProvider provider)

Parameters

format
A numeric format string.
format
A numeric format string.
provider
An object that supplies culture-specific formatting information.

Returns

The string representation of the value of this instance, as specified by format and provider.

Exceptions

TypeReason
FormatException format is invalid.

Remarks

The ushort.ToString(string, IFormatProvider) method formats a ushort value in a specified format by using the System.Globalization.NumberFormatInfo object of a specified culture. If you want to use default format or culture settings, use the other overloads of the ushort.ToString(string) method, as follows:

Default ("G") format

Default (current) culture

ushort.ToString

Default ("G") format

A specific culture

ushort.ToString(IFormatProvider)

A specific format

Default (current) culture

ushort.ToString(string)

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 null, the return value of the current ushort 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 IFormatProvider.GetFormat(Type) method returns a System.Globalization.NumberFormatInfo object that provides culture-specific information about the format of the string returned by this method. When the ushort.ToString(string, IFormatProvider) method is invoked, it calls the provider parameter's IFormatProvider.GetFormat(Type) method and passes it a Type object that represents the System.Globalization.NumberFormatInfo type. The IFormatProvider.GetFormat(Type) method then returns the System.Globalization.NumberFormatInfo object that provides information for formatting the current ushort value, such as the group separator symbol or the decimal point symbol. There are three ways to use the provider parameter to supply formatting information to the ushort.ToString(string, IFormatProvider) method:

If provider is null, the formatting of the returned string is based on the System.Globalization.NumberFormatInfo object of the current culture.

Requirements

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