什么时候应该使用前缀递减,什么时候应该使用后缀递减?
对于以下代码片段,我应该使用前缀递减还是后缀递减?
static private void function(int number)
{
charArr = new char[number];
int i = 0;
int tempCounter;
int j = 0;
while(charrArr!=someCharArr)
{
tempCounter = number - 1;
password[tempCounter] = element[i%element.Length];
i++;
//This is the loop the I want to use the decrementing in.
//Suppose I have a char array of size 5, the last element of index 5 is updated
//in the previous statement.
//About the upcoming indexes 4, 3, 2, 1 and ZERO.
//How should I implement it?
// --tempCounter or tempCounter-- ?
while (charArr[--tempCounter] == element[element.Length - 1])
{
}
}
}
tempCounter = number;
、password[tempCounter - 1]
和charArr[--tempCounter]
,尽管while
循环将在一个未初始化的数组上工作,而且tempCounter
可能会变成负数。 - sjngm