How to increment a number with leading zeros

I’ve needed to increment a number by one while keeping the leading zeros. For example 0001, 0002, 0003, 0004, and so on. I wasn’t sure of a sure way to do this in C# but I found the following works very well.

nextNumber.ToString().PadLeft(4, Convert.ToChar(“0”))

Disposing of objects in SharePoint

Adding sections and links to the Site Settings page