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.