麻煩各位大佬幫我看看這里哪里出錯(cuò)了,運(yùn)行完會(huì)報(bào)錯(cuò)
using System;
using System.Text.RegularExpressions;
namespace _1901203021_廖海鵬
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? Console.Write("身份證號(hào)碼:");
? ? ? ? ? ? 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("身份證輸入錯(cuò)誤,請(qǐng)重新輸入");
? ? ? ? ? ? //? ? 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("校驗(yàn)成功,此身份證號(hào)為真");
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.WriteLine("校驗(yàn)失敗,此身份證號(hào)為假");
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? }
? ? }
2019-12-05
你這寫(xiě)的是什么鬼?????
2019-12-02
剛剛發(fā)錯(cuò)了,是這個(gè),為什么會(huì)跳出錯(cuò)誤?
2019-12-02
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? Console.Write("身份證號(hào)碼:");
? ? ? ? ? ? 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("身份證輸入錯(cuò)誤,請(qǐng)重新輸入");
? ? ? ? ? ? //? ? 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("校驗(yàn)成功,此身份證號(hào)為真");
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.WriteLine("校驗(yàn)失敗,此身份證號(hào)為假");
? ? ? ? ? ? }
? ? ? ? }