You do not have indices in a foreach loop, you can use the variable itself:
foreach (var x in query)
{
}
for (int i = 0; i < query.Count(); ++i)
{
var x = query[i];
}
If you really need the current index, then you can create a variable and increment it in the loop:
int index = -1;
foreach (var x in query)
{
++index;
}