生成6位数字

Mir*_*aig 1 c#

我正从数据库中检索一些记录,我追加到一些字符串 - 例如:

spouse counter=1;
counter=1+counter;
Run Code Online (Sandbox Code Playgroud)

然后我得到customerID以下方式:

customerID = "AGP-00000" + counter;
Run Code Online (Sandbox Code Playgroud)

这样customerID就可以了AGP-000001.

对于计数器值2- customerID字符串将是AGP-000002.

我的问题是,如果计数器10那么customer IDAGP-0000010,我希望它是AGP-000010.

我怎样才能确保customer ID总是如此AGP-000010

Hab*_*bib 12

int  number = 1;
string customerID = "AGP-" + number.ToString("D6");
Run Code Online (Sandbox Code Playgroud)

customerID将是: "AGP-000001"

请参阅:如何:使用前导零填充数字