Hi I'm creating a program that holds three arrays one for the persons last name, one for the points scored and one for the player number, now I've got all the arrays and everything done but I'm not sure as to how to return the 3 new arrays from my deletemethod so that I can pass it into my playerdelete method and I am also having troubles trying to replace the odd array value with a new one so that I can remove the player entry from the user entered list. Also I can't use objects.

any help or guidance would be appreciated

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

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

                }
                if (0 != 1) { newArray[0] = playerNumbers[0]; }
                {

                }
                if (0 != 1)
                {
                    newArray[0] = 12; //the value of playerNumbers[0]}


                }
                index++;
                if (index2 != playerCount) { newArray2[r] = playerLastName[index2]; }
                {
                }


                if (0 != 1) { newArray2[0] = playerLastName[0]; }
                {

                }
                if (0 != 1)
                {
                    newArray2[0] = null; 
                }
                index2++;
                if (index3 != playerCount) { newArray3[r] = playerPoints[index3]; }
                {

                }
                if (0 != 1) { newArray3[0] = playerPoints[0]; }
                {

                }
                if (0 != 1)
                {
                    newArray3[0] = 12; 


                }
                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");
        }

    }
}

Why can't you use objects? You're using them all over. Did you know that e.g. Int32 is an object?

If your delete method is in the same class as the rest of the code you could always declare the arrays as globals, making them available to all methods. Then nothing needs to be returned at all. Otherwise, as ddanbe asked, why are objects out?

FYI int[] IS a reference object, so if you change a value in the array, all objects that have access to the array also has access to the changes made. If you change the length of the array, you just created a new object, so if you change its values and then assign it to the passed array, then the calling routines don't have access unless you included the ref keyword.
As pointed out, everything is an object so you have to make clearer how you can't access objects and why.

        /// <summary>
        /// It is really handy to use intellisense to define what your code does,
        /// especially when going back to code you wrote five years ago
        /// to remind you after forgetting what you were doing back then
        /// </summary>
        /// <param name="playerNumbers"></param>
        /// <param name="playerCount"></param>
        /// <param name="playerLastName"></param>
        /// <param name="playerPoints"></param>
       static void ProcessDelete(ref int[] playerNumbers, ref int playerCount, ref String[] playerLastName, ref int[] playerPoints)
        {//Why ref playerCount when it never changes and why not set the new arrays to the playerCount?
            Int32?[] newArray = new int?[playerNumbers.Length]; String[] newArray2 = new String[playerLastName.Length]; int[] newArray3 = new int[playerPoints.Length];
            int index = 0;//note that newArray has been reset to a nullable int array and Int32 IS int
            int index2 = 0;
            int index3 = 0;
            int r = 0;//r is currently constant, either plan for it to change or hard-code
            int j = 0;
            int t = 0;
            while (index < playerNumbers.Length && index2 < playerLastName.Length && index3 < playerPoints.Length)
            {
                if (index != playerCount) { newArray[r] = playerNumbers[index]; }
                //{ Write out in comments what you want to do when you create dead code both to remind yourself
                // what you intended to do and other coders why you put dead code in a location
                //}
                if (0 != 1) 
                {//write out why you are putting in ineffective if statements and the plan to fix them
                    newArray[0] = playerNumbers[0];
                }
                //Better yet don't write an if statement, just why you think one should be here
                {//There should be a reason why the first number in the array is hard-coded to 12 and don't embed that code in a loop
                    newArray[0] = 12; //the value of playerNumbers[0]}
                }
                index++;
                if (index2 != playerCount) { newArray2[r] = playerLastName[index2]; }
                {//For instance r never changes and index2 is always incremented keep indexing changes together IE
                    //newArray2[r++] = playerLastName[index2++]; 
                }
                if (0 != 1) { newArray2[0] = playerLastName[0]; }
                {
                }
                if (0 != 1)
                {// it is impossible to set an int to null unless you tell the code it is nullable
                    newArray2[0] = null;
                }
                index2++;
                if (index3 != playerCount) { newArray3[r] = playerPoints[index3]; }
                {
                }
                if (0 != 1) { newArray3[0] = playerPoints[0]; }
                {
                }
                if (0 != 1)
                {
                    newArray3[0] = 12;
                }
                index3++;
            }
            playerPoints = newArray3;//Because playerPoints is passed by ref, the referencing code also has to call by ref and it's address is reset here
        }

Whoops I changed the arrays to ref, but didn't set them to be nullable, both the replacement and sending variable have to match their nullable state.

A lot more thought needs to be put into keeping everything in sync. Why do you want to set a value to null? int.MinValue is just as invalid and doesn't blow up if you don't accept negative numbers

When the global variable was referenced, the poster meant to set the arrays as static in the class but outside the calling routine. Don't send the arrays as parameters, just create the new work arrays in the routine, load the old and the new information you want to change and then just set the static arrays to the work arrays

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.