using System;
using System.Text.RegularExpressions;
namespace _1901203021_廖海鹏
{
class Program
{
static void Main(string[] args)
{
Console.Write("身份证号码:");
string id = Convert.ToString(Console.ReadLine());
string expression = @"^d{18}$";
if (Regex.IsMatch(id, expression) == false)
{
Console.Write(false);
}
int[] wi = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
char[] checkNum = { '1', '0', 'x', '9', '8', '7', '6', '5', '4', '3', '2' };
//while (System.Text.Encoding.Default.GetByteCount(id) != 18)
//{
// Console.WriteLine("身份证输入错误,请重新输入");
// id = Convert.ToString(Console.ReadLine());
//}
//char[] ID = id.ToCharArray();
int[] ID = new int[id.Length];
for (int i = 0; i < id.Length; i++)
{
int ii = Convert.ToInt32(id[i]);
ID[i] = ii;
}
int S = 0;
for (int x = 0; x < 17; x++)
{
int Ai = ID[x];//将ID声明为int
int Wi = wi[x];
S += Ai * Wi;
}
int Y = S % 11;
Y = Convert.ToInt32(checkNum[Y]);
if (ID[18] == Y)
{
Console.WriteLine("校验成功,此身份证号为真");
}
else
{
Console.WriteLine("校验失败,此身份证号为假");
}
}
}
}
你这写的是什么鬼?????
刚刚发错了,是这个,为什么会跳出错误?
static void Main(string[] args)
{
Console.Write("身份证号码:");
string id = Convert.ToString(Console.ReadLine());
string expression = @"^d{18}$";
if (Regex.IsMatch(id, expression) == false)
{
Console.Write(false);
}
int[] wi = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
char[] checkNum = { '1', '0', 'x', '9', '8', '7', '6', '5', '4', '3', '2' };
//while (System.Text.Encoding.Default.GetByteCount(id) != 18)
//{
// Console.WriteLine("身份证输入错误,请重新输入");
// id = Convert.ToString(Console.ReadLine());
//}
char[] _id = id.ToCharArray();
int[] ID = new int[_id.Length];
for (int i = 0; i < _id.Length; i++)
{
int ii = Convert.ToInt32(_id[i]);
ID[i] = ii;
}
int S = 0;
for (int x = 0; x < 17; x++)
{
int Ai = ID[x];
int Wi = wi[x];
S += Ai * Wi;
}
int Y = S % 11;
char z = Convert.ToChar(Y);
z = checkNum[Y];
if (ID[18] == z)
{
Console.WriteLine("校验成功,此身份证号为真");
}
else
{
Console.WriteLine("校验失败,此身份证号为假");
}
}