Padding Zeroes to an integer value in C#

This content was proof-read by Grammarly. You can Try Grammary for FREE

If you need to prefix zeroes to an integer when converting it to string values , you can do that by using the PadLeft method in c#.

Just specify the number of characters to prefix (padding) and the charater to prefix to the method and you are done 🙂

Below is a sample sourcecode to demonstrate Padding Zeroes to an integer value in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
    static class Program
        static void Main()

        static void FormatString()
           int intVal = 100;
	       string formattedString = intVal.ToString().PadLeft(4,'0');
%d bloggers like this: