Format string/number "NNNNN"

c#, format, numbers, string

Solution

Just give format to `ToString` method

var str = count.ToString("00000");

Problem

I have to write a progression of number, having (each) 5 digit. My code is: ``` int count = 1; string labelCount = ""; foreach (var directory in folderList) { if (count < 10) { labelCount = "0000" + count.ToString(); } else if (count < 100) { labelCount = "000" + count.ToString(); } else if (count < 1000) { labelCount = "00" + count.ToString(); } else if (count < 10000) { labelCount = "0" + count.ToString(); } count++; } ``` but it doesnt looks so good in my opinion. Is there a way to format a number (adding 0xN to the left) or that's the only way?

Original source