Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8239809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:16:16+00:00 2026-06-07T20:16:16+00:00

Actually, it is a closer duplicate of: RemoveAll for ObservableCollections? Possible Duplicate: using LINQ

  • 0

Actually, it is a closer duplicate of:
RemoveAll for ObservableCollections?

Possible Duplicate:
using LINQ to remove objects within a List<T>

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?

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); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:16:18+00:00Added an answer on June 7, 2026 at 8:16 pm

    Apologies for the duplicate closure confusion. This question and marked answer will let you have extension method support for removing from observable collections:

    RemoveAll for ObservableCollections?

    It won’t give support for the from x in y syntax, but it will let you do:

    var c = new ObservableCollection<SelectableItem>();
    c.Remove(x => x.IsSelected);
    

    However, with the check x.PID == p.PID and the note about your other question… If in fact you want to remove items that are in both lists, this might not be the best option.

    The Except extension method will produce an enumerable of items that exclude items that are in the enumerable provided as an argument, in your case the second list. This method doesn’t mutate the existing enumerable, like most actions it returns a new one, so you would need to set that into a new ObservableCollection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually I am working on this for the last 3 or 4 weeks but
This question is pretty generic actually, but I'm really having trouble finding a good
Possible Duplicate: Why do some websites add “Slugs” to the end of URLs? This
Possible Duplicate: How to remove an XmlNode from XmlNodeList Hi, How can i delete
I'm not sure if this is a duplicate but if it is please feel
Possible Duplicate: /dev/null in Windows? I have a complex code that encodes input file
Actually I am stuck in middle of some mysql code. Can anyone suggest a
Actually ,i am working on a livechat application its works fine.This application is tabbed
Currently my code looks like this. It allows me to parse multiple parameters my
ive been thinking about this for hours and im not closer to an solution!

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.