Auto Generate alphanumeric Unique Id with C#

后端 未结 5 553
忘了有多久
忘了有多久 2021-01-18 12:49

Total string length is 5 chars

I have a scenario, ID starts with

A0001 and ends with A9999 then B0001 to B9999 until F0001 to f9999

after that

5条回答
  •  醉梦人生
    2021-01-18 13:12

    If you need to take it from the database and do this you can use something like the following.

    int dbid = /* get id from db */
    string id = dbid.ToString("X5");
    

    This should give you the format you are looking for as a direct convert from the DB ID.

提交回复
热议问题