2 回答

TA贡献1826条经验 获得超6个赞
您可以添加一个temp变量来存储的值CurrentValue。
int CurrentValue;
int PriorValue;
int temp = CurrentValue; //Add a temp variable to store CurrentValue.
CurrentValue = ChangingInt;
PriorValue = temp;

TA贡献1829条经验 获得超9个赞
int ChangingInt = ... // ChangingInt = A, PriorValue = B, CurrentValue = C
...
int PriorValue = CurrentValue // ChangingInt = A, PriorValue = C, CurrentValue = C
int CurrentValue = ChangingInt // ChangingInt = A, PriorValue = B, CurrentValue = A
PriorValue在运行之后,我们将不需要,因为我们只需要最后两个值,所以我们应该PriorValue首先将其更改为CurrentValue(因为CurrentValue需要成为new PriorValue),以进行重新分配。然后,我们可以更改CurrentValue为ChangingInt。
添加回答
举报