title: Why do I have to copy "this" when using LINQ in a struct (and is it OK if I do)?
body: <p>The code belows contains a simple LINQ query inside an immutable struct. </p>
  
  <pre><code>struct Point
  {
     static readonly List&lt;/*enum*/&gt; NeighborIndexes;
     //and other readonly fields!
  
      public IEnumerable&lt;FlatRhombPoint&gt; GetEdges()
      {
          return from neighborIndex in NeighborIndexes;
               select GetEdge(neighborIndex);
      }
  }
  </code></pre>
  
  <p>It does not compile.</p>
  
  <blockquote>
    <p>Anonymous methods, lambda expressions, and query expressions inside
    structs cannot access instance members of 'this'. Consider copying
    'this' to a local variable outside the anonymous method, lambda
    expression or query expression and using the local instead.</p>
  </blockquote>
  
  <p><strong>Does any one know why this is not allowed?</strong></p>
  
  <p>The fix the message suggests works fine:</p>
  
  <pre><code>    public IEnumerable&lt;FlatRhombPoint&gt; GetEdges()
      {
          var thisCopy = this;
  
          return from neighborIndex in NeighborIndexes;
               select thisCopy.GetEdge(neighborIndex);
      }
  </code></pre>
  
  <p>But is this standard practice? Are there reasons for not having queries like this in structs?
  (In the bigger scheme of things making a copy does not worry me performance-wise as such).</p>