Skip to main content

Microsoft Silverlight

Answered Question How to remove an item(s) from a Collection by queryRSS Feed

(0)

rasmasyean
rasmasyean

Member

Member

81 points

165 Posts

How to remove an item(s) from a Collection by query

How do you go about querying for, and then removing an item(s) from a collection?

swo
swo

Contributor

Contributor

2107 points

340 Posts

Answered Question

Re: How to remove an item(s) from a Collection by query

Hi

With collection (List, Dictionary....)?

However must be similar than :

To search ??collection.FindFirst(x => x.??? == ??  ) or ??collection.Single(x => x.?? ? ??)  

To delete ???collection.Remove(item) or ???collection.RemoveAt(2)

If this has answered your question, please click on "mark as answer" on this post. Thank you!

Wolfgang (SWO) - www.EasyByte.at


Jeremy Likness
Jeremy L...

Member

Member

326 points

57 Posts

Answered Question

Re: How to remove an item(s) from a Collection by query

First, you need to create a separate list of items to be removed. The first pass from the query, you can insert items into the list, like this:

List<string> days = new List<string> {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
IEnumerable<string> daysStartWithT =
                                from day in days
                                where day.StartsWith("T")
                                select day;

foreach(var day in daysStartWithT)
{
   days.Remove(day);
}
 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities