C# .NET Add Leading Zero to numeric string

By SP

This will show you how to add leading zero (prefix) to numeric value in C#

int sequenceNumber = 5;
string id = string.Format("{0}", sequenceNumber.ToString().PadLeft(2, '0'));

This will return Id = "05";

if you write

int sequenceNumber = 15 ;

then output will be ==> "15"

C# .NET Add Leading Zero to numeric string  (3514 Views)