数组保持重置为零 [英] Array keeps resetting to zero
问题描述
我创建了一个使用属性的方法,然后将该属性插入数组.此属性来自另一个类玩家",我试图获取该数组来存储每个玩家的总数,但是当它增加到下一个玩家时,它将其他玩家重置为零.
i've created a method that uses a property and then inserts that property into an array. this property is from another class "player" and I am trying to get the array to store the totals for each player, however when it increments to the next player it resets the other players to zero.
private void GetGrandTotal()
{
int[] grandTotals = new int[players.Count];
grandTotals[currentPlayerIndex] = currentPlayer.GrandTotal;
}
CurrentPlayerIndex是一个将当前玩家索引保存在绑定列表中的变量.
CurrentPlayerIndex is a variable that holds the current players index in a binding list.
推荐答案
这是因为每次调用该方法时都要重新初始化数组,因此请全局一次一次并在方法,只需将元素添加到数组中
This is because you are re initializing array each time you call the method, so declare and initialize the array globally ONCE and in the method, just add elements to the array
这篇关于数组保持重置为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!