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

3

我是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'"

请问有什么建议可以解决这个问题吗?

谢谢。

Luke


loq[i] = (Qualifying)num; - Joel Coehoorn
1个回答

4
loq[i] = (Qualifying)num;

应该是

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

loq 存储的是字符串类型,而你试图传入一个 Qualifying 枚举类型。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接