Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ';的最佳重载方法';有一些无效的参数_C#_Operator Overloading - Fatal编程技术网

C# ';的最佳重载方法';有一些无效的参数

C# ';的最佳重载方法';有一些无效的参数,c#,operator-overloading,C#,Operator Overloading,我创建了一个播放器类,我试图使用我的播放器类为菜单驱动的播放器程序创建和插入一个播放器,但我保留了错误: 'Assignment_7.Program.GetInsertIndex(int Assignment_7.Player,ref int)'的最佳重载方法对我的InsertPlayer和ProcessCreate方法具有一些无效参数 任何帮助都将不胜感激 static void ProcessCreate(Int32 number, String firstName, String las

我创建了一个播放器类,我试图使用我的播放器类为菜单驱动的播放器程序创建和插入一个播放器,但我保留了错误: 'Assignment_7.Program.GetInsertIndex(int Assignment_7.Player,ref int)'的最佳重载方法对我的InsertPlayer和ProcessCreate方法具有一些无效参数

任何帮助都将不胜感激

 static void ProcessCreate(Int32 number, String firstName, String lastName, Int32 goals,
        Int32 assists, Player[] players, ref Int32 playerCount, Int32 MAXPLAYERS)
    {

        if (playerCount < MAXPLAYERS)
        {
            Console.WriteLine("\nCreate Player: please enter the player's number");
            number = Int32.Parse(Console.ReadLine());
            if (GetPlayerIndex(number, firstName, lastName, goals, assists, players, playerCount) == -1)
            {
                Console.WriteLine("\nCreate Player: please enter the player's First Name");
                 firstName = Console.ReadLine();
                 Console.WriteLine("\nCreate Player: please enter the player's First Name");
                 lastName = Console.ReadLine();
                Console.WriteLine("\nCreate Player: please enter the player's goals");
                goals = Int32.Parse(Console.ReadLine());
                Console.WriteLine("\nCreate Player: please enter the player's goals");
                assists = Int32.Parse(Console.ReadLine());
                InsertPlayer(number, firstName, lastName, goals, assists, players, ref playerCount);
                Console.WriteLine("\nCreate Player: Number - {0}, First Name - {1},LastName - {2} Goals - {3}, Assists {4} created successfully", number,firstName, lastName, goals, assists);
                Console.WriteLine();
            }
            else
                Console.WriteLine("\nCreate Player: the player number already exists");
        }
        else
            Console.WriteLine("\nCreate Player: the player roster is already full");

    }


    //Inserts the player at the correct location in the tables based on order of ascending player number
    //Unless the insert location is at the end, this requires shifting existing players down in order to make room 
    //Inserts the player at the correct location in the tables based on order of ascending player number
    //Unless the insert location is at the end, this requires shifting existing players down in order to make room 
    static Int32 InsertPlayer(Int32 number, String firstName, String lastName, Int32 goals,
        Int32 assists, Player[] players, ref Int32 playerCount)
    {
        Int32 insertIndex, shiftCount;
   ---> insertIndex = GetInsertIndex(number, players, playerCount); <--- Error
        for (shiftCount = playerCount; shiftCount > insertIndex; shiftCount--)
            players[shiftCount] = players[shiftCount - 1];
        players[insertIndex] = new Player(firstName, lastName, number, goals, assists);
        playerCount++;
        return insertIndex;
    }





    //Returns the index of the first player number in the table that is greater
    //than the player number to be inserted
    static Int32 GetInsertIndex(Int32 number,Player[] players,
        ref Int32 playerCount)
    {
        Int32 index = 0;
        bool found = false;
        while (index < playerCount && found == false)
            if (players[index].Number > number)
                found = true;
              else
                index++;
        return index;
    }

    //Returns the index of the player number in the table 
    //or -1 if the number is not found
    static Int32 GetPlayerIndex(Int32 number, String firstName, String lastName, Int32 goals,
        Int32 assists, Player[] players, ref Int32 playerCount)
    {
        Int32 index = 0;
        bool found = false;
        while (index < playerCount && found == false)
             if (players[index].Number == number)
                found = true;
              else
                index++;
        if (found == false)
            index = -1;
        return index;
    }
static void ProcessCreate(Int32 number、String firstName、String lastName、Int32目标、,
Int32助攻,球员[]球员,裁判Int32球员计数,Int32最大球员)
{
如果(玩家计数<最大玩家)
{
Console.WriteLine(“\n创建播放机:请输入播放机号码”);
number=Int32.Parse(Console.ReadLine());
如果(GetPlayerIndex(数字、名字、姓氏、进球、助攻、球员、球员计数)=-1)
{
Console.WriteLine(“\n创建播放器:请输入播放器的名字”);
firstName=Console.ReadLine();
Console.WriteLine(“\n创建播放器:请输入播放器的名字”);
lastName=Console.ReadLine();
Console.WriteLine(“\n创建玩家:请输入玩家的目标”);
goals=Int32.Parse(Console.ReadLine());
Console.WriteLine(“\n创建玩家:请输入玩家的目标”);
assists=Int32.Parse(Console.ReadLine());
插入球员(号码、名字、姓氏、进球、助攻、球员、裁判球员计数);
Console.WriteLine(“\n创建玩家:编号-{0},名字-{1},姓氏-{2}进球-{3},助攻{4}创建成功”,编号,姓氏,姓氏,进球,助攻);
Console.WriteLine();
}
其他的
Console.WriteLine(“\n创建播放器:播放器编号已存在”);
}
其他的
Console.WriteLine(“\n创建玩家:玩家名册已满”);
}
//根据播放机编号的升序将播放机插入表中的正确位置
//除非插入位置在末尾,否则需要将现有玩家下移以腾出空间
//根据播放机编号的升序将播放机插入表中的正确位置
//除非插入位置在末尾,否则需要将现有玩家下移以腾出空间
静态Int32 InsertPlayer(Int32编号、字符串名、字符串名、Int32目标、,
Int32助攻,球员[]球员,裁判Int32球员计数)
{
Int32 insertIndex,shiftCount;
--->insertIndex=GetInsertIndex(数字、玩家、玩家计数);insertIndex;移位计数--)
玩家[shiftCount]=玩家[shiftCount-1];
球员[插入索引]=新球员(名字、姓氏、号码、进球、助攻);
playerCount++;
返回插入索引;
}
//返回表中第一个大于的玩家编号的索引
//而不是要插入的播放器号码
静态Int32 GetInsertIndex(Int32编号,播放器[]播放器,
参考Int32播放器计数)
{
Int32指数=0;
bool-found=false;
while(索引Number)
发现=真;
其他的
索引++;
收益指数;
}
//返回表中玩家编号的索引
//如果找不到数字,则为-1
静态Int32 GetPlayerIndex(Int32编号、字符串名、字符串名、Int32目标、,
Int32助攻,球员[]球员,裁判Int32球员计数)
{
Int32指数=0;
bool-found=false;
while(索引
方法
GetInsertIndex
要求最后一个参数带有
ref
修饰符,但您是按值传递它。您应该在传递的参数之前添加
ref

insertIndex = GetInsertIndex(number, players, ref playerCount);
//                                      here  ^^^
根据,在声明和调用时都必须使用
ref

要使用ref参数,方法定义和调用方法都必须显式使用ref关键字

因此,在您的情况下,您应该替换

insertIndex = GetInsertIndex(number, players, playerCount);
insertIndex = GetInsertIndex(number, players, playerCount);


当您在方法中使用
ref
时,参数必须在调用中使用它。然后替换


这两个重载都与
GetInsertIndex(数字、玩家、玩家计数)不兼容。也许你的意思是
GetInsertIndex(数字、玩家、参考玩家计数)
insertIndex = GetInsertIndex(number, players, playerCount);
insertIndex = GetInsertIndex(number, players, ref playerCount);