title: How does deferred LINQ query execution actually work?
body: <p>Recently I faced such question:
  <code>What numbers will be printed considering the following code:</code></p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          int[] numbers = { 1, 3, 5, 7, 9 };
          int threshold = 6;
          var query = from value in numbers where value &gt;= threshold select value;
  
          threshold = 3;
          var result = query.ToList();
  
          result.ForEach(Console.WriteLine);
          Console.ReadLine();
      }
  }
  </code></pre>
  
  <p>Answer: <code>3, 5, 7, 9</code></p>
  
  <p>Which was quite surprising to me. I thought that <code>threshold</code> value will be put onto stack at the query construction and later at execution time, that number will be pulled back and used in the condition..which didn't happen.</p>
  
  <p>Another case (<code>numbers</code> is set to <code>null</code> just before execution):</p>
  
  <pre><code>    static void Main(string[] args)
      {
          int[] numbers = { 1, 3, 5, 7, 9 };
          int threshold = 6;
          var query = from value in numbers where value &gt;= threshold select value;
  
          threshold = 3;
          numbers = null;
          var result = query.ToList();
          ...
      }
  </code></pre>
  
  <p>Seems to have no effect on the query. It prints out exactly the same answer as in previous example.</p>
  
  <p>Could anyone help me understand what is really going on behind the scene? Why changing <code>threshold</code> has the impact on the query execution while changing <code>numbers</code> doesn't?</p>