我正在尝试从另一个类中调用一个方法。p.players()
当我选择此菜单选项时应该打开:
static void Main(string[] args)
{
Enumfactory.Position choice;
Enumfactory.Location location;
Player p = new Player();
Console.WriteLine("Please choose from one of the following:");
Console.WriteLine("1. GoalKeeper");
Console.WriteLine("2. Defender");
Console.WriteLine("3. Midfielder");
Console.WriteLine("4. Striker");
choice = ((Enumfactory.Position)(int.Parse(Console.ReadLine())));
string exit = "";
while (exit != "Y")
{
switch (choice)
{
case Enumfactory.Position.GoalKeeper:
//assigning the actual position
p.Position = Enumfactory.Position.GoalKeeper;
p.players();
break;
这是我在 Player 类中的方法:
public string[] players()
{
List<string> PlayerList = new List<string>();
Player player = new Player();
string enterplayer = "";
while (enterplayer == "Y")
{
Console.WriteLine("Please enter the teamnumber of your player");
player.teamNumber = int.Parse(Console.ReadLine());
Console.WriteLine("Please enter the name of your player");
player.name = Console.ReadLine();
Console.WriteLine("Please enter the surname of your player");
player.surname = Console.ReadLine();
Console.WriteLine("Enter the age of your player");
player.age = int.Parse(Console.ReadLine());
Console.WriteLine("Please enter the goals the player scored");
player.goalsScored = int.Parse(Console.ReadLine());
PlayerList.Add(player.teamNumber.ToString());
PlayerList.Add(player.name);
PlayerList.Add(player.surname);
PlayerList.Add(player.age.ToString());
PlayerList.Add(player.goalsScored.ToString());
Console.WriteLine("Do you wish to enter another player? Y/N");
enterplayer = Console.ReadLine();
}
foreach (var item in PlayerList)
{
Console.WriteLine("to view your player");
Console.Write("{0}", item);
}
Console.ReadKey();
return player.players();
}