C# Byte ToString(String)

Description

Byte ToString(String) converts the value of the current Byte object to its equivalent string representation using the specified format.

Syntax

Byte.ToString(String) has the following syntax.


public string ToString(
  string format
)

Parameters

Byte.ToString(String) has the following parameters.

  • format - A numeric format string.

Returns

Byte.ToString(String) method returns The string representation of the current Byte object, formatted as specified by the format parameter.

Example

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.


using System;/*from  w  w  w.j av  a  2 s  .  c om*/
public class MainClass{
  public static void Main(String[] argv){  
        string[] formats = {"C3", "D4", "e1", "E2", "F1", "G", "N1", 
                            "P0", "X4", "0000.0000"};
        byte number = 240;
        foreach (string format in formats){
           Console.WriteLine("'{0}' format specifier: {1}", format, number.ToString(format));
        }
  }
}
    

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