您需要将计数器存储在方法外部(例如在SQL Server中),然后返回客户ID。下面是一个示例代码:
private static readonly object o = new object();
public static int GenerateNextCustomerId() {
lock (o) {
// Write code to get the next counter from db in this method
var counter = GetNextCounter();
var nextCustomerId = string.Format("{0}{1}{2}",
DateTime.Now.Year, DateTime.Now.Month,
counter.ToString().PadLeft(4, '0'));
// Write code to increment the counter and save to db in this method
IncrementCounter();
return int.Parse(nextCustomerId);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句