tags:

views:

18

answers:

1

I have a foreach loop that declares a variable I never use, but I don't know how to get around it.

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

I never use "i" - but I need an iterator in the loop. So how do I get rid of this error?

+2  A: 

Warning is reasonable. You don't need foreach at all. Looks like you try to loop times equal to size of collection. You should use for:

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