C# - increment number and keep zeros in front

前端 未结 5 599
再見小時候
再見小時候 2021-02-07 10:17

I need to make a 40 digit counter variable. It should begin as 0000000000000000000000000000000000000001
and increment to
000000000000000000000000000

5条回答
  •  太阳男子
    2021-02-07 10:56

    Use the integer and format or pad the result when you convert to a string. Such as

    int i = 1;
    string s = i.ToString().PadLeft(40, '0');
    

    See Jeppe Stig Nielson's answer for a formatting option that I can also never remember.

提交回复
热议问题