我的程序没有重载方法

时间:2014-11-02 19:52:47

标签: c#

我正在创建一个包含三个阵列的程序:一个用于人的姓氏,一个用于得分,一个用于玩家号码。现在,我已经完成了所有阵列和一切,但是当我尝试调用我的ProcessDelete方法时,我一直在使用

  

最佳重载方法匹配   ' playersystem6.program.ProcessDelete(int [],ref int)'有一些无效的   参数

正确方向的一些指导确实会有所帮助。

static Int32[] ProcessDelete(Int32[] playerNumbers, ref Int32 playerCount)
        {
            Int32[] newArray = new Int32[playerNumbers.Length - 1]; 

            int index = 0;
            int j = 0;
            while (index < playerNumbers.Length)
            {
                if (index != playerCount)
                {
                    newArray[j] = playerNumbers[index];
                    j++;
                }

                index++;
            }

            return newArray;          
        }

        static void DeletePlayer(Int32[] playerNumbers, String[] playerLastName, Int32[] playerPoints, ref Int32 playerCount, Int32 MAXPLAYERS)
        {
            int player;// Player number to delete
            int playerindex;//index of the player number in Array
            if (playerCount < MAXPLAYERS)
            {
                player = GetPositiveInteger("\nDelete Player: please enter the player's number");
                playerindex = ProcessDelete(playerNumbers, playerCount);

               if (playerindex != -1)
                {
                    {    
                        Console.WriteLine("\nDelete Player: Number - {0}, Name - {1}, Points - {2}", playerNumbers[playerindex], playerPoints[playerindex] );
                        Console.WriteLine("Succesfully Deleted");
                        Console.WriteLine();
                    }
                }
                else
                    Console.WriteLine("\nDelete Player: player not found");
            }
            else
                Console.WriteLine("\nDelete Player: the roster is empty");
        }
    }
}

1 个答案:

答案 0 :(得分:0)

在行中:

playerindex = ProcessDelete(playerNumbers, playerCount);

ref前添加playercount关键字,明确告诉它通过引用传递:

playerindex = ProcessDelete(playerNumbers, ref playerCount);