title: Replacing nested foreach with LINQ; modify and update a property deep within
body: <p>Consider the requirement to <em>change</em> a data member on one or more properties of an object that is 5 or 6 levels deep. </p>
  
  <p>There are sub-collections that need to be iterated through to get to the property that needs inspection &amp; modification.</p>
  
  <p>Here we're calling a method that cleans the street address of a Employee. Since we're changing data within the loops, the current implementation needs a <code>for</code> loop to prevent the exception:</p>
  
  <blockquote>
    <p>Cannot assign to "someVariable" because it is a 'foreach iteration variable'</p>
  </blockquote>
  
  <p>Here's the current algorithm (obfuscated) with nested <code>foreach</code> and a <code>for</code>.</p>
  
  <pre><code>foreach (var emp in company.internalData.Emps)
  {
      foreach (var addr in emp.privateData.Addresses)
      {
          int numberAddresses = addr.Items.Length;
  
          for (int i = 0; i &lt; numberAddresses; i++)
          {
              //transform this street address via a static method
              if (addr.Items[i].Type =="StreetAddress")
                 addr.Items[i].Text = CleanStreetAddressLine(addr.Items[i].Text);
          }
      }
  }
  </code></pre>
  
  <p><strong>Question:</strong>
  Can this algorithm be reimplemented using LINQ? The requirement is for the original collection to have its data changed by that static method call.</p>
  
  <p><strong>Update:</strong> I was thinking/leaning in the direction of a jQuery/selector type solution. I didn't specifically word this question in that way. I realize that I was over-reaching on that idea (no side-effects). Thanks to everyone! If there is such a way to perform a jQuery-like selector, please let's see it!</p>