2013-05-10 99 views
3

我是C#的新手,需要一些關於下面代碼的幫助。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’隱式轉換爲‘字符串’」

誰能請提供,以便任何建議解決這個問題。

謝謝。

盧克

+0

這是78線嗎? – akonsu 2013-05-10 21:42:42

+0

'loq [i] =(合格)數量;' – 2013-05-10 21:44:27

回答

4
loq[i] = (Qualifying)num; 

應該

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

loq存儲字符串類型,你想放的Qualifying枚舉。

+0

非常感謝! – LukeBorg 2013-05-10 23:55:35