Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过c生成唯一的3字符城市代码#_C#_Asp.net_Sql Server 2008 - Fatal编程技术网

C# 通过c生成唯一的3字符城市代码#

C# 通过c生成唯一的3字符城市代码#,c#,asp.net,sql-server-2008,C#,Asp.net,Sql Server 2008,我必须生成一个3个字符的城市代码,如“001”到“999”。在这之后,它应该是'a01'到'a99',然后是'b01'到'b99',依此类推。如何通过c#代码生成它并将其插入city表。我正在使用sql server 2008与linq一起构建 var list = (from number in Enumerable.Range(1, 99) select string.Format("{0:000}", number)) // 1 - 999 .Union (

我必须生成一个3个字符的城市代码,如“001”到“999”。在这之后,它应该是'a01'到'a99',然后是'b01'到'b99',依此类推。如何通过c#代码生成它并将其插入city表。我正在使用sql server 2008与linq一起构建

var list = (from number in Enumerable.Range(1, 99) select string.Format("{0:000}", number)) // 1 - 999
                .Union (from number in Enumerable.Range(1, 26 * 100) where number % 100 != 0 select string.Format("{0}{1:00}", (char)(97 + number / 100), number % 100)); // ?01 - ?99 where ? is a to z

但是请注意,您使用的城市代码对人类来说毫无意义,您应该决定另一种使用的编码方案。

对不起,我是说城市欢迎使用SO:SE。该网站不是免费的代码源,你需要提供你的代码,这有问题,或者没有按预期工作。看,你为什么要做这样的事?在数据库中使用int-identity列有什么问题?我知道了,使用枚举是更好的选择。我也会考虑你的意见。