C# Byte ToString(IFormatProvider)

Description

Byte ToString(IFormatProvider) converts the numeric value of the current Byte object to its equivalent string representation using the specified culture-specific formatting information.

Syntax

Byte.ToString(IFormatProvider) has the following syntax.


public string ToString(
  IFormatProvider provider
)

Parameters

Byte.ToString(IFormatProvider) has the following parameters.

  • provider - An object that supplies culture-specific formatting information.

Returns

Byte.ToString(IFormatProvider) method returns The string representation of the value of this object in the format specified by the provider parameter.

Example

The following example iterates an array of byte values and displays each of them to the console by calling the ToString(IFormatProvider) method with different format providers.


using System;/*ww w  . ja v a2  s  . c  o m*/
using System.Globalization;
public class MainClass {
  public static void Main(String[] argv){  
        byte[] bytes = {0, 1, 14, 168, 255};
        CultureInfo[] providers = {new CultureInfo("en-us"), 
                                   new CultureInfo("fr-fr"), 
                                   new CultureInfo("de-de"), 
                                   new CultureInfo("es-es")};
        foreach (byte byteValue in bytes)
        {
           foreach (CultureInfo provider in providers)
              Console.Write("{0,3} ({1})      ", 
                            byteValue.ToString(provider), provider.Name);
        
           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