title: Using LINQ to delete an element from a ObservableCollection Source
body: <blockquote>
    <p><strong>Actually, it is a closer duplicate of:</strong><br>
    <a href="https://stackoverflow.com/questions/5118513/removeall-for-observablecollections">RemoveAll for ObservableCollections?</a></p>
  </blockquote>
  
  <p><strike></p>
  
  <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/853526/using-linq-to-remove-objects-within-a-listt">using LINQ to remove objects within a List&lt;T&gt;</a><br>
    </strike></p>
  </blockquote>
  
  
  
  <p>This is the code I'm using, but its not very readable. Can I use LINQ to shorten the code below while still having the same functionality?</p>
  
  <pre><code>int index = 0;
  int pos = 0;
  
  foreach (var x in HomeViewModel.RecentPatients)
  {
     if (x.PID == p.PID)
         pos = index;
     else
         index++;
  
  }
  
  HomeViewModel.RecentPatients.RemoveAt(pos); 
  </code></pre>