Format byte in default format and leading zeros in CSharp

Description

The following code shows how to format byte in default format and leading zeros.

Example


using System;/* ww  w. j ava 2  s.co  m*/

public class Example
{
   public static void Main()
   {

        byte[] numbers = { 0, 16, 104, 213 };
        foreach (byte number in numbers) {
           // Display value using default formatting.
           Console.Write("{0,-3}  -->   ", number.ToString());

           // Display value with 3 digits and leading zeros.
           Console.Write(number.ToString("D3") + "   ");

        } 
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var