foreach (char vowel in "aeiou")
{
query = query.Where(c => c != vowel);
}
foreach (char n in query)
{
Console.Write(n + " ");
}
I don't know how foreach loop have inside it but I suspect that it's single variable of given type.
So in when adding a reference in your Where lamba to it your adding same reference.
Change reference in next foreach iteration and all values will change cause of all are pointing to same variable.
Temp variable will solve this since in each iteration you are declaring new with diffrent variable.
And it is query it is not executed till time when you get it's value so something along the lines:
char[] s = "Not what you might expect".ToArray();
foreach (char vowel in "aeiou")
{
s = s.Where(c => c != vowel).ToArray();
}
foreach (char n in query)
{
Console.Write(n + " ");
}
will solved it to.