title: LINQ | ArgumentOutOfRangeException: Index was out of range
body: <pre><code>for (int i = 0; i &lt; intFeatureIDs.Count; i++) {
      slots_for = slots_for.Where(s =&gt; s.featureSlotMapping.Any(fsm =&gt; fsm.featureID == intFeatureIDs[i]));
  }
  </code></pre>
  
  <p>Here, intFeatureID.Count is 2. And throws below exception.</p>
  
  <h1>Exception:</h1>
  
  <p>Message=An exception was thrown while attempting to evaluate a LINQ query parameter expression. To show additional information call EnableSensitiveDataLogging() when overriding DbContext.OnConfiguring.</p>
  
  <p>Inner Exception 1:
  ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.  </p>
  
  <p>If intFeatureIDs.Count == 1, there is no issue.</p>
  
  <p>Also, If I comment out the for loop, and manually run the code twice, it will work...</p>
  
  <pre><code>slots = slots.Where(s =&gt; s.featureSlotMapping.Any(fsm =&gt; fsm.featureID == intFeatureIDs[1]));
  slots = slots.Where(s =&gt; s.featureSlotMapping.Any(fsm =&gt; fsm.featureID == intFeatureIDs[2]));
  </code></pre>
  
  <p>Any comments are much appreciated.</p>