C#

要写1个程式是叫 用户 输入他们的名字 ,还有 ID numberusing System;namespace IC_Systems
{ class Class1
{

[STAThread]
static void Main(string[] args)
{
Console.Write("Please enter your full name: ");
string name = Console.ReadLine();

Console.Write("Please enter your IC#: ");
string icnum = Console.ReadLine();
Console.WriteLine
("Name of resident: {0}", name);
Console.WriteLine
("Date of birth: 19{0}" ,idum);
Console.WriteLine
("Gender: {0}" ,sex);
Console.WriteLine
("type: {0}" ,type); }
}
}名字部分已经完成了
现在剩下id number 的部分不会
Console.Write("Please enter your ID number number: " ;
   string idnum = Console.ReadLine();我要将 user 输入的id号码 做计算
要怎樣分?user 输入的號碼 是 12個號碼   xxxxxx-xx-xxxx 
int idnum [11]  这样对吗?
(输入时 ,   不要有 -  如果有 - 出 Console.Write("Error"); (然后叫用户 再输入过 ,不要终止程式)
然后做计算例如     861122339916得到的答案是 生日日期 = 22 号 11 月 86年
意思说 array 0,1 是年份 ,array 2,3 是月 , array 4,5 是 日期
之后 array 6 , 7 要组合 起来
int sum = ( idnum [ 6 ] * 10 ) + idnum [ 7 ] ;然后做1堆 case 
例如 861122339916 的array 6 和7 加起来是 30 +3 = 33
case 1 01, 21, 22, 23, 24A  = Applecase 202, 25, 26, 27 ,33A = Orange 等等 ...33 在 case 2 , 所以 A = Orange
还有就是最后1个 号码 弟 12个 号码 是算单数 or 双数 
单数=男生 双数 = 女生if idnum [11]  = ( ( idnum [ 11 ] % 2 ) == 0 ) ;
then gender = femaleeals male
--------------------------------------------例: 名字 aabbcc  IDnum :    810503 78 4443
    答案 名: aabbcc
答案1: 03日05月81年
答案2: orange
答案3: 男--------------------------------------------
不懂C# 的coding 要怎麼寫  有人可以教嗎?讲到好像很乱,希望有人看的明白

解决方案 »

  1.   

    楼主,是要做身份证号的切割识别吧,用SPLIT函数切开就得了
      

  2.   

    / 基本上、 还是糊涂了、。做成winform 直观多了、。控制台 有没什么大用处、
      

  3.   

    看明白了。
    结合楼主的代码写了一个框子,具体内容自己添加。
     class Class1
        {
            [STAThread]
            static void Main(string[] args)
            {
                bool canExit = false;
                
                //这个循环
                while (!canExit )
                {
                    Console.Write("Please enter your full name: ");
                    string name = Console.ReadLine();                Console.Write("Please enter your IC#: ");
                    string icnum = Console.ReadLine();                //xxxxxx xx xxxx check
                    Int64 res;
                    if (Int64.TryParse(icnum, out res))
                    {
                        //id读取成功
                        canExit = true;
                    }
                    else 
                    {
                        Console.Write("Error");
                        continue; 
                    }                //自己的逻辑处理
                    //                Console.WriteLine
                        ("Name of resident: {0}", name);
                    Console.WriteLine
                        ("Date of birth: 19{0}", idum);
                    Console.WriteLine
                        ("Gender: {0}", sex);
                    Console.WriteLine
                        ("type: {0}", type);
                }        }
      

  4.   

    好像是一个身份加密识别的处理。用正则表达式匹配格式,用String.Replace("-")处理掉-线,然后按位置切割处理就可以了,用String.Substring()取得相应位置的字符,再执行相关处理。
      

  5.   

    Int64.TryParse 他给我error 'long' does not contain a definition for 'TryParse' @.@
      

  6.   

    Int64 res;
    if (Int64.TryParse(icnum, out res)) 
    改成-----〉 
    long res;
    if(long.TryParse(icnum,out res));
      

  7.   

    还是一样呢 =(
    'long' does not contain a definition for 'TryParse'
      

  8.   


            static void Main(string[] args)
            {
                string name = "";
                while (name.Length == 0)
                {
                    Console.Write("Please enter your full name: ");
                    name = Console.ReadLine();
                }            string icnum = "";
                while (icnum.Length == 0)
                {
                    Console.Write("Please enter your IC#: ");
                    icnum = Console.ReadLine().Trim();
                    if (icnum.Length == 12 && icnum.IndexOfAny(new char[]{'-', '.'}) < 0)
                    {
                        long nNum = 0;
                        if (long.TryParse(icnum, out nNum))
                        {
                            break;
                        }
                    }
                    Console.WriteLine("Error");
                    icnum = "";
                }            string year = icnum.Substring(0, 2);
                string month = icnum.Substring(2, 2);
                string day = icnum.Substring(4, 2);
                string sum = icnum.Substring(6, 2);
                bool gender = (icnum[11] % 2 == 1);            string a = "";
                if ("01, 21, 22, 23, 24".IndexOf(sum) > 0)
                {
                    a = "apple";
                }
                else if ("02, 25, 26, 27 ,33 ".IndexOf(sum) > 0)
                {
                    a = "orange";
                }
                else
                {
                    a = "unknown";
                }            Console.WriteLine("答案 名: {0}\n", name);
                Console.WriteLine("答案1:{0}日{1}月{2}年\n", day, month, year);
                Console.WriteLine("答案2:{0}\n", a);
                Console.WriteLine("答案3:{0}\n", gender ? "男" : "女");            Console.ReadLine();
            }
      

  9.   

    string a;
    string A= icnum.Replace("-","");请问一下如果我这样写, 例如 881122-11
    array 6和7  会是 1吗? 
      

  10.   


    谢谢可是不懂为什么
    if (long.TryParse(icnum, out nNum)) 还是有error一直说 'long' does not contain a definition for 'TryParse'我是用 Microsoft Visual Studio .NET 2003 ,是不是版本的问题?
      

  11.   

    using System;namespace IC_Systems_V2
    { class Class1
    {

    [STAThread]
    static void Main(string[] args)
    {
    string name = "";
    while (name.Length == 0)
    {
    Console.Write("Please enter your full name: ");
    name = Console.ReadLine();
    }
    try 
    { string icnum = "";
    while (icnum.Length == 0)

    {
    Console.Write("Please enter your IC#: ");
    icnum = Console.ReadLine().Trim();
    if (icnum.Length == 12 && icnum.IndexOfAny(new char[]{'-', '.'}) < 14)
    {

    }


    else 
    {
    string b= icnum.Replace("-",string.Empty);


    }
    {
    string b= icnum.Replace("-",string.Empty);  string year = b.Substring(0, 2);
    string month = b.Substring(2, 2);
    string day = b.Substring(4, 2);
    string sum = b.Substring(6, 2);
    bool gender = (b[11] % 2 == 1);
    string c;
    if ("01, 21, 22, 23, 24".IndexOf(sum) > 0)
    {
    c = "apple";
    }
    else if ("02, 25, 26, 27 ,33 ".IndexOf(sum) > 0)
    {
    c = "orange";
    }
    else
    {
    c = "unknown";
    } Console.WriteLine("\nName: {0}", name);
    Console.WriteLine("DOB:{0}/{1}/{2}", day, month, year);
    Console.WriteLine("CITY:{0}", c);
    Console.WriteLine("Gender:{0}", gender ? "Boy" : "Girl");
    } } }
    catch 
    {
    Console.WriteLine("\nuser may input the incorrect format, please try again.");
    } }
    }
    }如果这样写用户输入 xxxxxxxxxxxxx or xxxxxx-xx-xxxx 都可以计算
    可是如果用户输入超过位数 xxxxxx-xx-xxxxxxxx  还是会计算计算 =.="
    如果用户输入 xxxxxxxxxxasdasfsdf  (数字 + 英文 ) ,程式不会出错误,而且还是继续计算 @_@"要怎么改?