This question already has an answer here:
- C# convert int to string with padding zeros?
You can do this with a string datatype. Use the
myString.PadLeft(myString.Length + 5, '0');
There’s no such concept as an integer with padding. How many legs do you have – 2, 02 or 002? They’re the same number. Indeed, even the “2” part isn’t really part of the number, it’s only relevant in the decimal representation.
If you need padding, that suggests you’re talking about the textual representation of a number… i.e. a string.
You can achieve that using string formatting options, e.g.
string text = value.ToString("0000000");
string text = value.ToString("D7");
An integer value is a mathematical representation of a number and is ignorant of leading zeroes.
You can get a string with leading zeroes like this:
The concept of leading zero is meaningless for an int, which is what you have. It is only meaningful, when printed out or otherwise rendered as a string.
Forgot to end the double quotes!