CA1804:声明一个从未使用过的变量

时间:2010-09-30 21:56:45

标签: fxcop

我有一个foreach循环,它声明了一个我从未使用的变量,但我不知道如何绕过它。

foreach (string i in stringCollection){
    some other stuff
}

我从不使用“i” - 但我需要循环中的迭代器。那么如何摆脱这个错误?

1 个答案:

答案 0 :(得分:4)

警告是合理的。您根本不需要foreach。看起来你试图循环时间等于集合的大小。您应该使用for

for (int i = 0; i < stringCollection.Count; i++)
{
    some other stuff
}