更新方法不更新 [英] update method not updating

查看:88
本文介绍了更新方法不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个玩家类,我正在尝试使用我的玩家类为我的菜单驱动的玩家程序更新玩家。我希望能够让用户输入一个玩家编号并询问他们是否要更新玩家助手和目标然后显示更新的玩家信息,如果玩家不存在则会显示消息玩家不存在。出于某种原因,当我输入我创建的其中一个玩家的玩家编号时,当他到达编辑目标Y / N并且我选择了Y时它表示玩家不存在而不是让我编辑目标。仍然说即使它刚刚创建,播放器也不存在。我不知道如何解决这个问题。



任何帮助都将不胜感激。



I created a player class and I am trying to use my player class to update a player for my menu driven player program. I want to be able to have the user enter a player number and ask if they want to update the player assists and goals then display the updated player information and if the player doesn't exist then it would display the message player does not exist. For some reason when I enter a player number of one of the players I created when it gets to the edit goals Y/N and I chose Y it says the player doesn't exist instead of letting me edit the goals.it still says that the player does not exist even though it was just created. I am not sure on how to fix this.

Any help would be appreciated.

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
            string answer, answer2;
            

            if (playerCount < MAXPLAYERS )
            {
                Console.WriteLine("\nUpdate Player: please enter the player's number");
                number = Int32.Parse(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 {3} assists", players[playerindex].Number,
                            players[playerindex].Goals, players[playerindex].Assists, players[playerindex].Points());
                    Console.ReadLine();
                 
                    Console.WriteLine("\nEdit Goals?: Y/N");
                    answer = Console.ReadLine();
                    if (answer.Equals('Y'))
                    {
                        Console.WriteLine("\nUpdate Player: please enter the player's new Goal total");
                        goals = Int32.Parse(Console.ReadLine());
                        Console.WriteLine("\nEdit Assists?: Y/N");
                        answer2 = Console.ReadLine();
                        if (answer2.Equals('Y'))
                        {

                            Console.WriteLine("\nUpdate Player: please enter the player's new Assists total");
                            assists = Int32.Parse(Console.ReadLine());
                            /*
                            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");
            }
        }

推荐答案

您正在将字符串值与char值进行比较(您将答案声明为字符串然后将其与char值相等)

此外,此比较区分大小写。请确保输入'Y'而不是'y'(或任何你想要的东西)



以下应该可以使用;

You are comparing a string value to a char value (you declared answer as string and then equalling it with a char value)
Also, this comparison is case-sensitive. Please make sure you are typing 'Y' and not 'y' (or whatever you are expecting)

The below should work;
answer.Equals("Y")





如果对您有帮助,请将答案标记为正确。



谢谢。



Please mark the answer as correct if it helps you.

Thanks.


这篇关于更新方法不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆