我正在尝试将数字 0-28,110,000 写入文本文件,用 0 填充较小的数字(信不信由你,这不是家庭作业)。
Desired Output
00000001
00000002
00000003
...
28109999
28110000
但是当我将其写入文本文件时,输出如下所示:
00000001
00000002
00000003
...
27145011
27
最后一个数字停在中间。任何人都可以看到为什么会发生这种情况以及我该如何纠正它?
完整代码
long lastCode = 28110000;
int padSize = (lastCode == 0) ? 1 : (int)Math.Log10(lastCode) + 1;
String filename = @"C:\Documents and Settings\All Users\Desktop\" + lastCode + "_sequentialCodes.txt";
StreamWriter writer = new StreamWriter(filename, false, Encoding.ASCII);
writer.AutoFlush = true;
for (int i = 1; i < lastCode + 1; i++)
{
writer.WriteLine(i.ToString().PadLeft(padSize, '0'));
if (i % 100 == 0)
{
Console.Write(".");
}
}
writer.Close();
Console.WriteLine();
Console.WriteLine(lastCode + " codes written to \n" + filename);
Console.Read();