I'm creating a program that holds three arrays: one for the person's last name, one for the points scored and one for the player number. Now, Ive got all the arrays and everything done but My ProcessDelete method isn't removing the items in the array and I can't figure out why?

Any help would be appreciated

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

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

                index++;
            }

            while (index2 < playerLastName.Length)
            {
                if (index2 != playerCount)
                {
                    newArray2[k] = playerLastName[index2];
                    k++;
                }

                index2++;
            }
              while (index3 < playerLastName.Length)
            {
                if (index3 != playerCount)
                {
                    newArray3[t] = playerPoints[index3];
                    t++;
                }

                index3++;
            }
            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 = GetPlayerIndex(player, playerNumbers, playerCount);


               if (playerindex != -1)
                {

                    {

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

    }
}

What is your logic to remove an element from an Array? Here you construct your logic with three new Arrays, NewArray, NewArray2 and NewArray3, not with the Arrays where you already store the data. The removal activity of your process never reflects on the originals, because you tried to construct a new Array from the original, never try to remove an element.
You can do it by removing through the element index value or re-construct the originals with your new arrays by a loop as you did.

  1. DeletePlayer() never does anything with the array returned by ProcessDelete().
  2. As Shark_1 said, since you are passing the array PlayerLastname by value to ProcessDelete(), you get a copy, not references to the actual array.
  3. What are array2 and array3 being used for in ProcessDelete()? They accomplish nothing.

You need to totally rethink your logic in this code. It cannot work as I think you wish.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.