方法的类型参数''(& # 39;不能从用法中推断.)

本文关键字:用法 类型参数 方法 不能 | 更新日期: 2023-09-27 18:05:07

我正在尝试使用对象数组来存储数据来构建联系人管理器程序。我需要查看一个报告,显示可用的联系人摘要,然后有一个菜单,让用户与程序进行交互。但是由于某种原因,当我调用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;
        }                   
    }

方法的类型参数''(& # 39;不能从用法中推断.)

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

ProcessMenuItem(Char menuItem, List<contactList> contactList)

ProcessMenuItem(Char menuItem, List<Contact> contactList)