我想在 c# WPF 中创建返回 10 个数字值的函数。它包含如下一位数(静态)-> 'G'两位数(动态)-> 当前年份的“19”两位数(动态)-> 当前月份的“04”五位数字(动态)-> '00284' <- 从 sql 表返回。这个的长度必须是固定的。上面代码的返回值是'G190400284'(我想要这个值作为返回值)如果我的五位数(4.)值应该是1然后它返回'G1904000001'
1 回答

噜噜哒
TA贡献1784条经验 获得超7个赞
像那样的东西?
using System;
public class Program
{
public static void Main()
{
Console.WriteLine(CreateString(1));
Console.WriteLine(CreateString(284));
}
public static string CreateString(int id)
{
var n = DateTime.Now;
return "G" + n.Year.ToString().Substring(2,2) + n.Month.ToString().PadLeft(2,'0') + id.ToString().PadLeft(5,'0');
}
}
// This returns
// G190400001
// G190400284
https://dotnetfiddle.net/oteEpe
- 1 回答
- 0 关注
- 66 浏览
添加回答
举报
0/150
提交
取消