我创建了一个播放器类,我正在尝试将我的播放器类与我的菜单驱动播放器程序一起使用,但我不断收到错误'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;
}
}
答案 0 :(得分:1)
您在MAXPLAYERS
ProcessMenuItem
)
ProcessMenuItem(menuItem, number, firstName, lastName, goals, assists, players, ref playerCount, MAXPLAYERS)
其他一些建议:
ProcessMenuItem
返回int
,而不是使用ref
参数MAXPLAYERS
是const
成员,那么它不需要是ProcessMenuItem
的参数(因为它现在正在隐藏const
成员)。< / LI>
Player
类并将其传递给ProcessMenuItem
而不是几个参数。