안녕하세요 저는 사람성에 대해 하나씩 3 개의 배열을 저장하는 프로그램을 만들고 있습니다. 하나는 점수를 매기는 점수이고 다른 하나는 플레이어 수를 나타내는 것입니다. 사용자가 플레이어 번호를 입력했을 때 삭제 방법을 만들었습니다. 플레이어 번호, 성 및 입력 한 플레이어 번호를 삭제합니다. 그러나 플레이어 번호를 입력하여 플레이어 데이터를 삭제하면 전체 배열이 지워집니다. 입력 된 플레이어 번호의 플레이어 번호, 성 및 포인트를 지울 수 있지만 전체 배열이 아닌 이러한 항목 만 지울 수 있기를 원합니다. 어떻게하는지 잘 모르겠습니다.배열에서 선택한 요소를 지우는 방법
정말 만족하고 감사합니다 도움이 될 올바른 방향으로 어떤 도움이나지도
static void 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 = Array.IndexOf(playerNumbers, 0);
{
for (int i = 0; i < playerNumbers.Length; i++)
playerNumbers[i] = 0;
}
for (int i = 0; index < playerLastName.Length; index++)
playerLastName[i] = " ";
for (int i = 0; i < playerPoints.Length; i++)
playerPoints[i] = 0;
}
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");
}
}
}
바로 대답은이 세 가지를 가진 플레이어 클래스를 하비브 제안 일을하고 만드는 것입니다
그냥 제안, 특성을 가진 클래스'Player' 만들기'PlayerNumber'는'Name'와'Score'하고 대신 여러 배열을 가진 인덱스를 기반으로 그들을 관리하는'목록 을'유지. –
Habib
좋은 패턴이 아닙니다. 단일 개체를 사용하십시오. –
'{}'의 사용법을 고치고 불필요한 대괄호를 추가하지 마십시오. 코드를 정리하고 다시 포맷하십시오. – MethodMan