Link to home
Start Free TrialLog in
Avatar of eshurak
eshurakFlag for United States of America

asked on

Remove item from List<> using delegates

Using C# and VS2005 in an ASP.NET project I need to remove an item from a list<>. Here's what I've got so far.  The problem is my list is based on a custom object (PartnerRecord) so I'm trying to use delegates to create a record to remove, but I'm open to anything.


            List<PartnerRecord> results = Session["FilteredPartners"] as List<PartnerRecord>;

                        results.Remove(delegate(PartnerRecord pr1)
                        { return pr1.ID.Equals(ResultsGrid.Items[i].KeyValues.ToString(), StringComparison.CurrentCultureIgnoreCase); });
ASKER CERTIFIED SOLUTION
Avatar of Anurag Thakur
Anurag Thakur
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eshurak

ASKER

Thanks Ragi,

The problem was in my delegate.


PartnerRecord pr = results.Find(delegate(PartnerRecord pr1) { return pr1.ID.Equals(ResultsGrid.Items[i].KeyValues.Substring(5,36)); });
results.Remove(pr);

Open in new window