C# UInt16 ToString(String, IFormatProvider)

Description

UInt16 ToString(String, IFormatProvider) converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.

Syntax

UInt16.ToString(String, IFormatProvider) has the following syntax.


public string ToString(
  string format,
  IFormatProvider provider
)

Parameters

UInt16.ToString(String, IFormatProvider) has the following parameters.

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

Returns

UInt16.ToString(String, IFormatProvider) method returns The string representation of the value of this instance, as specified by format and provider.

Example

The following example displays a 16-bit unsigned integer value by using the standard numeric format specifiers and a number of specific CultureInfo objects.


using System;/*from  www  .  ja v  a  2s . c o m*/
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CultureInfo[] cultures = { CultureInfo.CreateSpecificCulture("en-US"), 
                                 CultureInfo.CreateSpecificCulture("fr-FR"), 
                                 CultureInfo.CreateSpecificCulture("es-ES") };
      string[] specifiers = {"G", "C", "D4", "E2", "F", "N", "P", "X2"}; 
      ushort value = 12345;

      foreach (string specifier in specifiers)
      {
         foreach (CultureInfo culture in cultures)
            Console.WriteLine("{0,2} format using {1} culture: {2, 16}",  
                              specifier, culture.Name, 
                              value.ToString(specifier, culture));
         Console.WriteLine();
      }
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version