title: Collection modified during foreach error
body: <p>I know you can't modify a collection during a <code>foreach</code>, but I should be able to set variable values of the underlying iterator through it. For some reason the method below, every time it executes is giving be the "Collection was modified..." error:</p>
  
  <pre><code>private static IInstrument AdjustForSimpleInstrument(DateTime valueDate, IInstrument temp)
  {
      var instr = temp;
      foreach (var component in instr.Components)
      {
          component.Schedule.ScheduleRows.RemoveAll(
                  sr =&gt;
                  ((sr.Payment != null) &amp;&amp; (sr.Payment.PaymentDate != null) &amp;&amp;
                   (sr.Payment.PaymentDate.AdjustedDate.Date &lt;= valueDate.Date)));
  
          if (
              !component.ScheduleInputs.ScheduleType.In(ComponentType.Floating, ComponentType.FloatingLeg,
                                                        ComponentType.Cap, ComponentType.Floor)) continue;
  
          foreach (var row in component.Schedule.ScheduleRows)
          {
              var clearRate = false;
              if (row.Payment.CompoundingPeriods != null)
              {
                  if (row.Payment.CompoundingPeriods.Count &gt; 0)
                  {
                      foreach (
                          var period in
                              row.Payment.CompoundingPeriods.Where(
                                  period =&gt; ((FloatingRate)period.Rate).ResetDate.FixingDate &gt; valueDate))
                      {
                          period.Rate.IndexRate = null;
                          clearRate = true;
                      }
                  }
              }
              else if (row.Payment.PaymentRate is FloatingRate)
              {
                  if (((FloatingRate)row.Payment.PaymentRate).ResetDate.FixingDate &gt; valueDate)
                      clearRate = true;
              }
              else if (row.Payment.PaymentRate is MultipleResetRate)
              {
                  if (
                      ((MultipleResetRate)row.Payment.PaymentRate).ChildRates.Any(
                          rate =&gt; rate.ResetDate.FixingDate &gt; valueDate))
                  {
                      clearRate = true;
                  }
              }
              if (clearRate)
              {
                  row.Payment.PaymentRate.IndexRate = null;
              }
          }
      }
      return temp;
  }
  </code></pre>
  
  <p>Am I just missing something easy here? The loop that is causing the exception is the second, this one:</p>
  
  <pre><code>foreach (var row in component.Schedule.ScheduleRows)
  </code></pre>