Skip to main content
Home Forums General Silverlight Getting Started How to remove an item(s) from a Collection by query
2 replies. Latest Post by Jeremy Likness on November 4, 2009.
(0)
rasmasyean
Member
82 points
165 Posts
11-03-2009 4:54 PM |
How do you go about querying for, and then removing an item(s) from a collection?
swo
Contributor
2127 points
340 Posts
11-03-2009 5:02 PM |
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)
Jeremy L...
326 points
57 Posts
11-04-2009 8:06 AM |
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); }