Is this linq statement gonna be executed everytime in each loop? Does somehow the for loop store the linq result?
for(int i = 0; i < mylist.Where(x => x > 10).ToList().Count; i++)
Sorry in case of a duplicate
I ran the following code in LINQPad:
for(int i = 0; i < 10.Dump(); i++)
{
}
The result was:
So, i think the answer is yes, it will execute it multiple times.
Yes it would work but I would suggest to better try to store it in a int variable
int k = mylist.Where(x => x > 10).ToList().Count;
for(int i = 0; i < k; i++)
This makes it more readable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With