Replacing if(x) Foreach() with Foreach.Where(x)

Viewed 10975

Probably a stupid question but I have a lot of:

if(X)
{
  foreach(var Y in myList.Where(z => z == 1)
  {
  }
} 

constructs in some code
Is replacing it with

foreach(var Y in myList.Where(z => X && z == 1) { }

insane?

It is probably less readable, but will the compiler optimize it to make it pretty much the same code?

3 Answers
Related