Я создал класс игрока и сделал массив из этого класса для моей системы управления с помощью меню. Я пытаюсь спросить пользователя y/n, если они хотят обновить цели, и если они вводят y им вводит новую сумму, и если нет отображения сообщения, а затем попросите их обновить передачи и сделать то же самое для справки, но когда я помещаю n в программу, он продолжает говорить, что исключение было unhanded. Необработанное исключение типа «System.Exception 'произошел в SystemPlayer.exe. II не уверен в том, как это исправитьЗадающий пользователь y/n при обновлении информации
любая помощь будет оценена
static void ProcessUpdate(Int32 number, String firstName, String lastName,
Int32 goals, Int32 assists, Player[] players,
ref Int32 playerCount, Int32 MAXPLAYERS)
{
int playerindex;//index of the player number in Array
char answer, answer2;
if (playerCount == 0)
{
Console.WriteLine("\nUpdate Player: roster is empty");
}
else if (playerCount < MAXPLAYERS)
{
number = IOConsole.GetInt32("\nUpdate Player: please enter the player's number: ");
//number = IOConsole.GetInt32(message);
//Console.ReadLine();
playerindex = GetPlayerIndex(number, firstName, lastName, goals, assists, players, ref playerCount);
if (playerindex != -1)
{
Console.WriteLine("\nUpdate Player: Player {0} currently has {1} goals and {2} assists \nEdit Goals?: Y/N: ", players[playerindex].Number,
players[playerindex].Goals, players[playerindex].Assists);
answer = Convert.ToChar(Console.ReadLine());
if (answer.Equals('Y') || answer.Equals('y'))
{
goals = IOConsole.GetInt32("\nUpdate Player: please enter the player's new Goal total: ");
if (goals < 0)
{
Console.WriteLine("Goals cannot have a negative number");
}
else if (answer.Equals('N') || answer.Equals('n'))
{
Console.WriteLine("Goals Not Updated");
}
}
answer2 = IOConsole.GetChar("\nEdit Assists?: Y/N: ");
if (answer2.Equals('Y') || answer2.Equals('y'))
{
assists = IOConsole.GetInt32("\nUpdate Player: please enter the player's new Assists total: ");
if (assists < 0)
{
Console.WriteLine("assists Cannot have assists negative number");
}
if (answer2.Equals('N') || answer2.Equals('n'))
{
Console.WriteLine("Assists Not Updated");
}
}
//players[playerindex].LastName = lastName;
//players[playerindex].FirstName = firstName;
players[playerindex].Goals = goals;
players[playerindex].Assists = assists;
Console.WriteLine("\n{0,7} {1,-20}{2, -20}{3,8}{4,8}{5,8}\n", "Number", "First Name", "Last Name", "Goals", " Assists", "Points");
Console.WriteLine("{0,7} {1,-20}{2, -20}{3,8}{4,8}{5,8}",
players[playerindex].Number, players[playerindex].FirstName, players[playerindex].LastName,
players[playerindex].Goals, players[playerindex].Assists, players[playerindex].Points());
Console.WriteLine("Sucessfully Updated!");
Console.WriteLine();
}
else
Console.WriteLine("\nUpdate Player: the player number does not exists");
}
else
Console.WriteLine("\nUpdate Player: the player does not exist in the roster");
}
Вот где мой игрок класса, где ошибка исключение произошло
//Public Goals accessor
public Int32 Goals
{
get
{
//Return member variable value
return _goals;
}
set
{
//Validate value and throw exception if necessary
if (value <= 0)
throw new Exception("Goals must be a positive number");
else
//Otherwise set member variable value
_goals = value;
}
}
Что такое IOConsole и что такое GetPlayerIndex, с помощью Equals, используйте перегруженный вызов метода, который использует перечисление StringComparison и использует CurrentCultureIgnoreCase для удаления дублирования – Fredou