适用于';..的最佳过载方法';有一些无效的参数

本文关键字:参数 无效 最佳 适用于 方法 | 更新日期: 2023-09-27 18:30:04

我创建了一个播放器类,并试图将我的播放器类与菜单驱动的播放器程序一起使用,但我一直收到错误"Assignment_7.program.ProcessCreate(int,string,string,int,int,Assignment_7.player,ref-in,int)"的最佳重载方法与我试图与菜单一起使用的方法有一些无效参数

如有任何帮助,我们将不胜感激。

//MAXPLAYERS常量是物理表大小const Int32 MAXPLAYERS=23;

    //Declare the player tables
    Player[] players = new Player[MAXPLAYERS];
    //Keep track of the actual number of players (i.e. logical table size)
    Int32 playerCount = 0;
    //Main Driver
    char menuItem;
    Console.WriteLine("Welcome to the player system...'n");
    menuItem = GetMenuItem();
    while (menuItem != 'X')
    {
        ProcessMenuItem(menuItem, number, firstName, lastName, goals, assists, players, ref playerCount);
        menuItem = GetMenuItem();
    }
    Console.WriteLine("'nThank you, goodbye");
    Console.ReadLine();
}
//new Player(number, firstName, lastName, goals, assists)
//Returns either a 'C', 'R', 'U', 'D', 'L', or 'X' to the caller
static char GetMenuItem()
{
    char menuItem;
    DisplayMenu();
    menuItem = char.ToUpper(char.Parse(Console.ReadLine()));
    while (menuItem != 'C'
        && menuItem != 'L' && menuItem != 'X' && menuItem != 'R' && menuItem != 'U' && menuItem != 'D')
    {
        Console.WriteLine("'nError - Invalid menu item");
        DisplayMenu();
        menuItem = char.ToUpper(char.Parse(Console.ReadLine()));
    }
    return menuItem;
}
static void DisplayMenu()
{
    Console.WriteLine("'nPlease pick an item:");
    Console.WriteLine("C - Create Player");
    Console.WriteLine("R - Retrive Player");
    Console.WriteLine("U - Update Player");
    Console.WriteLine("D - Delete Player");
    Console.WriteLine("L - List Players");
    Console.WriteLine("X - Exit");
}
//Routes to the appropriate process routine based on the user menu choice
static void ProcessMenuItem(Char menuItem, Int32 number, String firstName, String lastName, Int32 goals,
    Int32 assists, Player[] players, ref Int32 playerCount, Int32 MAXPLAYERS)
{
    switch (menuItem)
    {
        case 'C':
            ProcessCreate(number, firstName, lastName, goals, assists, ref playerCount, players, MAXPLAYERS);
            break;
        case 'L':
            ProcessList(number, firstName, lastName, goals, assists,players, ref playerCount);
            break;
        case 'R':
            ProcessRetrive(number, lastName, firstName, goals,  assists, ref playerCount MAXPLAYERS);
            break;
        case 'U':
            ProcessUpdate(number, firstName,lastName,goals ,assists, ref playerCount, MAXPLAYERS);
            break;
        case 'D':
            DeletePlayer(number, firstName,lastName,goals ,assists, ref playerCount, MAXPLAYERS);
               break;
    }
}

适用于';..的最佳过载方法';有一些无效的参数

调用ProcessMenuItem 时缺少最后一个参数(MAXPLAYERS

ProcessMenuItem(menuItem, number, firstName, lastName, goals, assists, players, ref playerCount, MAXPLAYERS)

其他一些建议:

  • 使ProcessMenuItem返回int,而不是使用ref参数
  • 如果MAXPLAYERSconst成员,那么它不需要是ProcessMenuItem的参数(现在它隐藏了const成员)
  • 考虑创建一个Player类并将其传递给ProcessMenuItem,而不是几个参数