using System;
using System.Threading;
namespace KeyboardRecord
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
string a = Console.ReadLine();
if (a.Length!=15)
{
Console.WriteLine("Please input correct idnumber");
}
else
{
Console.WriteLine(getCheckCode(a));
}
}
static string getCheckCode(string sfzh)
{
char[] strJiaoYan = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
int[] intQuan = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1};
string strTemp;
int intTemp = 0;
strTemp = sfzh.Substring(0,6) + "19" + sfzh.Substring(6);
for (int i=0;i<=strTemp.Length-1;i++)
{
intTemp += int.Parse(strTemp.Substring(i,1))*intQuan[i];
}
intTemp = intTemp % 11;
return strTemp + strJiaoYan[intTemp];
}
}
}
此博客展示了一段C#代码,用于实现身份证号校验码的计算。代码通过读取用户输入的字符串,判断长度是否为15位,若符合则调用函数计算并输出包含校验码的完整号码,涉及字符串处理和算法逻辑。
1万+





