订购带有前导零的序列号(Ordered serial numbers with leading zeroes)

我正在尝试生成一个带有前导零的有序序列号列表,如下所示:

00000000001 00000000002 00000000003 ... ... 00000000101 00000000102 00000000103 ... ... 00099999991 00099999992 ... ... 99999999999 - END

我最好的尝试是:

long fn; for (fn = 100000000000; fn < 999999999999; fn++) { Console.WriteLine(fn); }

我想将所有这些序列号写入文件,虽然我不希望它看起来像从1 - 999999999999计算,但更像是从000000000000到999999999999生成的序列号。

I'm trying to generate a list of ordered serial numbers with leading zeroes like this:

00000000001 00000000002 00000000003 ... ... 00000000101 00000000102 00000000103 ... ... 00099999991 00099999992 ... ... 99999999999 - END

My best attempt is this:

long fn; for (fn = 100000000000; fn < 999999999999; fn++) { Console.WriteLine(fn); }

I want to write all these serial numbers to a file though I don't want it to look like it counted from 1 - 999999999999, but more like serial numbers generating from 000000000000 to 999999999999.

最满意答案

一种选择是用零填充:

Console.WriteLine(fn.ToString().PadLeft(12, '0'));

如果fn = 123,这将打印出000000000123 。

One option is to pad with zeroes:

Console.WriteLine(fn.ToString().PadLeft(12, '0'));

If fn = 123, this will print out 000000000123.

订购带有前导零的序列号(Ordered serial numbers with leading zeroes)

我正在尝试生成一个带有前导零的有序序列号列表,如下所示:

00000000001 00000000002 00000000003 ... ... 00000000101 00000000102 00000000103 ... ... 00099999991 00099999992 ... ... 99999999999 - END

我最好的尝试是:

long fn; for (fn = 100000000000; fn < 999999999999; fn++) { Console.WriteLine(fn); }

我想将所有这些序列号写入文件,虽然我不希望它看起来像从1 - 999999999999计算,但更像是从000000000000到999999999999生成的序列号。

I'm trying to generate a list of ordered serial numbers with leading zeroes like this:

00000000001 00000000002 00000000003 ... ... 00000000101 00000000102 00000000103 ... ... 00099999991 00099999992 ... ... 99999999999 - END

My best attempt is this:

long fn; for (fn = 100000000000; fn < 999999999999; fn++) { Console.WriteLine(fn); }

I want to write all these serial numbers to a file though I don't want it to look like it counted from 1 - 999999999999, but more like serial numbers generating from 000000000000 to 999999999999.

最满意答案

一种选择是用零填充:

Console.WriteLine(fn.ToString().PadLeft(12, '0'));

如果fn = 123,这将打印出000000000123 。

One option is to pad with zeroes:

Console.WriteLine(fn.ToString().PadLeft(12, '0'));

If fn = 123, this will print out 000000000123.