C#简单控制台应用程序枚举问题

时间:2013-05-10 21:40:31

标签: c# console-application

我是C#的新手,需要以下代码的帮助。

此控制台应用程序应该存储5个不同对应阵列中的5个申请人的详细信息。最后,这应该允许我通过声明我的数组后创建的菜单来查看申请人的姓名。请注意,该计划尚未完成。

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;

  namespace ConsoleApplication1
 {
 enum Qualifying {Diploma=1, Bachelor=2, Degree=3, Masters_Degree=4, PhD=5};
 class Program
 {
    static void Main(string[] args)
    {
        string[] ids = new string[5];
        string[] names = new string[5];
        string[] dobs = new string[5];
        string[] yoe = new string[5];
        string[] loq = new string[5];

        bool x = true;
        while (x)
        {
            Console.WriteLine("Please choose an option");
            Console.WriteLine("1.Add Applicants Details");
            Console.WriteLine("2.Display Applicants names");
            Console.WriteLine("3.Search for Applicant details");
            Console.WriteLine("4.Modify Applicant details");
            Console.WriteLine("5.Exit");
            int choice = Convert.ToInt32(Console.ReadLine());

            switch (choice)
            {
                case 1:
                    {
                        Console.WriteLine("Please fill in the following: ");
                        for (int i = 0; i < ids.Length; i++)
                        {
                            Console.WriteLine("Enter 5 ID Card noS");
                            string id = Console.ReadLine();

                            ids[i] = id;
                        }

                        for (int i = 0; i < names.Length; i++)
                        {
                            Console.WriteLine("Enter 5 Full Names");
                            string name = Console.ReadLine();

                            names[i] = name;
                        }

                        for (int i = 0; i < dobs.Length; i++)
                        {
                            Console.WriteLine("enter 5 Date of births");
                            string dob = Console.ReadLine();

                            dobs[i] = dob;
                        }

                        for (int i = 0; i < yoe.Length; i++)
                        {
                            Console.WriteLine("Enter 5 Years of experience");
                            string years = Console.ReadLine();

                            yoe[i] = years;
                        }

                            Console.WriteLine("Enter 5 Levels of Qualification, Choose from the list and press the number according to the qualification held:\n1=Diploma, 2=Bachelor, 3=Degree, 4=Masters Degree, 5=PhD");

                            for(int i=0; i<5; i++)
                            {
                                int num=Convert.ToInt32(Console.ReadLine());                              
                                {
                                if (num <= 4)
                                {
                                    loq[i] = (Qualifying)num;
                                }
                                else
                                    Console.WriteLine("Invalid input");
                                }
                            }
                        break;
                    }
                case 2:
                    {
                        for (int i = 0; i < names.Length; i++)
                        {
                            Console.WriteLine("The names of the students are " + names[i]);
                        }
                        break;
                    }
                case 3:
                    {
                        Console.WriteLine("Please enter the name of the applicant who you like to edit");
                    }
                    break;
                case 4:
                    {
                        Console.WriteLine("Input the applicants ID NUMBER for modification: ");
                        string id1 = Console.ReadLine();

                        //if (id1 == id)
                        //    Console.WriteLine("Full Name");
                        string name1 = Console.ReadLine();
                        Console.WriteLine("Date of birth");
                        string dob1 = Console.ReadLine();
                        Console.WriteLine("Years of experience");
                        int years1 = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Levels of Qualification, Choose from the list:\nDiploma, Bachelor, Degree, Master Degree, PhD");
                        string quals1 = Console.ReadLine();
                        break;
                    }

                case 5:
                    {
                        Console.WriteLine("You chose to quit. BYE =D");

                        x = false;
                        break;
                    }
            }
        }
    }
}
}

我在第78行说错:

“无法将类型'ConsoleApplication1.Qualifying'隐式转换为'string'”

任何人都可以提供任何建议以解决此问题。

谢谢。

1 个答案:

答案 0 :(得分:4)

loq[i] = (Qualifying)num;

应该是

loq[i] = ((Qualifying)num).ToString();

loq存储字符串类型,并且您尝试输入Qualifying的枚举。