0
안녕하세요 저는 성을위한 3 개의 배열을 보유하고있는 프로그램을 만들고 있습니다. 하나는 점수를 매기고 다른 하나는 플레이어 수를 나타냅니다. 이제는 모든 배열과 모든 것을 끝내지 만 확실하지는 않습니다. 어떻게 여러 배열에 대한 항목을 삭제할 것인지에 대해 설명합니다. 지금까지이게 내가 delete player 메소드에 대해 가지고있는 것입니다. 올바른 방향으로 인도하면 도움이되고 감사 할 것입니다.배열 여러 배열에서 항목을 삭제하는 방법?
static Int32[] ProcessDelete(Int32[] playerNumbers, String[] playerLastName, Int32[] playerPoints, ref Int32 playerCount)
{
Int32[] newArray = new int[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 = 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();
}
}
else
Console.WriteLine("\nDelete Player: player not found");
}
else
Console.WriteLine("\nDelete Player: the roster is empty");
}
}
}
어쩌면 배열은 당신의 사건에 대한 올바른 형식이 아닙니다. –
배열을이 용도로 사용하지 마십시오. 플레이어의 관련 데이터를 나타내는 클래스를 정의하십시오. –
'Player' 클래스는 관련 정보를 유지하고 List은 여러 플레이어를 더 쉽게 관리 할 수 있습니다. –
Plutonix