0
您好我正在創建一個程序,該程序包含三個數組,一個用於姓氏,一個用於分數得分和一個用於玩家號碼,現在我已經獲得了所有陣列並完成了所有事情,但我不確定我將如何刪除多個數組的條目。到目前爲止,這是我的刪除播放器方法。一些正確的方向的指導將真正幫助請和謝謝數組如何刪除多個數組中的條目?
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");
}
}
}
也許陣列是不是你的情況下正確的類型。 – 2014-11-02 16:50:08
不要爲此使用數組,請定義一個表達玩家相關數據的類。 – 2014-11-02 16:50:47
'玩家'類可以將相關信息保存在一起,並且列表可以更容易地管理多個玩家 –
Plutonix
2014-11-02 16:51:19