Use ToString() to format integers : Integer format « Data Type « C# / CSharp Tutorial






using System; 
 
class MainClass { 
  public static void Main() { 
    int x = 21; 

    string str = x.ToString("X"); 
    Console.WriteLine(str); 
 
    str = x.ToString("D12"); 
    Console.WriteLine(str); 
 
  } 
}
15
000000000021








2.10.Integer format
2.10.1.Use ToString() to format integers