方法的类型参数'' ('无法从使用中推断出来。)

时间:2015-07-28 02:26:57

标签: c#

我正在尝试使用对象数组构建一个联系人管理器程序来存储数据。我需要查看显示可用联系人摘要的报告,然后有一个菜单允许用户与该程序进行交互。 但出于某种原因,当我调用ProcessMenuItem方法时,我得到错误:

方法' managersApplication.Program.ProcessMenuItem(char,System.Collections.Generic.List)'的类型参数。无法从使用中推断出来。

任何指导都将不胜感激。

static void Main(string[] args)
    {


        //Declare the list

        List<Contact> contactList = new List<Contact>();

        Console.WriteLine("Contact List");

        //Main Driver
        char menuItem;
        Console.WriteLine("Welcome to the player system...\n");
        menuItem = GetMenuItem();
        while (menuItem != 'X')
        {

            ProcessMenuItem(menuItem, contactList);
            menuItem = GetMenuItem();

        }
        Console.WriteLine("\nThank you, goodbye");
        Console.ReadLine();
    }
    //Returns either a 'C', 'R', 'U', 'D', 'L', or 'X' to the caller
    static char GetMenuItem()
    {
        char menuItem;
        DisplayMenu();
        menuItem = char.ToUpper(IOConsole.GetChar("\nPlease pick an item: "));
        while (menuItem != 'C'
            && menuItem != 'R' && menuItem != 'Q' && menuItem != 'U' && menuItem != 'D' && menuItem != 'S' && menuItem != 'L' && menuItem != 'F' && menuItem != 'P' && menuItem != 'T')
        {
            Console.WriteLine("\nError - Invalid menu item");
            DisplayMenu();
            menuItem = char.ToUpper(IOConsole.GetChar("Enter option or M for menu:"));
        }
        return menuItem;
    }

    static void DisplayMenu()
    {
       Console.WriteLine("C-> Create Contacts");
       Console.WriteLine("R-> Remove Contacts");
       Console.WriteLine("U-> Update Contacts");
       Console.WriteLine("D -> Load data from file");
       Console.WriteLine("S-> Save data to file");
       Console.WriteLine("L-> View sorted by last name");
       Console.WriteLine("F-> View sorted by first name");
       Console.WriteLine("P-> View by partial name search");
       Console.WriteLine("T-> View by contact type");
       Console.WriteLine("Q-> Quit");
    }

    //Routes to the appropriate process routine based on the user menu choice
    static void ProcessMenuItem(Char menuItem, List<contactList> contactList)
    {
        switch (menuItem)
        {
            case 'C':
                createContact();
                break;
            case 'R':
                 removeContact();
                break;
            case 'U':
                updateContact();
                break;
            case 'D':
                LoadToFile();
                break;
            case 'S':
                saveToFile();
                break;

            case 'L':
                sortByLastName(contactList);
                break;
            case 'F':
                sortByFirstName(contactList);
                   break;
            case 'P':
                    DisplayList();
                   break;
            case 'T':
                   sortByContactType();
                   break;
            case 'Q':

                   break;

        }                   
    }

1 个答案:

答案 0 :(得分:0)

我认为你应该改变这一行:

ProcessMenuItem(Char menuItem, List<contactList> contactList)

ProcessMenuItem(Char menuItem, List<Contact> contactList)