1
我正在創建一個包含三個數組的程序:一個用於姓名,一個用於得分,一個用於玩家號碼。現在,我得到了所有數組,一切都完成了,但對於一些我的進程刪除方法不會從數組中刪除項目。我知道,我問過一個類似的問題,但我似乎無法弄清楚,爲什麼它不會刪除正確刪除方法不刪除
任何幫助,將不勝感激請和謝謝
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");
}
}
你有沒有調試你的代碼 – vallabha 2014-11-03 03:40:46
我沒有看到任何刪除操作在陣列上執行 – vallabha 2014-11-03 03:43:59
放置一些斷點,遍歷代碼,並找出是否正確的代碼甚至執行你期望它的方式。 – 2014-11-03 03:44:26