如何基于Pattern生成字符串

Rat*_*_Ge 0 c# string string-formatting

我有一个案例,我必须根据具体模式生成交易号码模式如下:

MA 0000000/dd/mm/YYYY/00000

其中第一个零是随机数,那么当前日期和最后一个零应该是增量的

(00001 ... 00010 ... 00100 ... 00578)

能否请您提供正确的方法来实施此案例.

Mar*_*ila 5

public static class Generator
{
    static int current = 0;
    static Random rand = new Random();

    public static string NextId()
    {
        return string.Format("MA {0:0000000}/{1}/{2:00000}", 
          rand.Next() % 100000,
          DateTime.Now.ToString("dd/MM/yyyy"),
          current++ );
    }
}
Run Code Online (Sandbox Code Playgroud)