Solved

Remove item from List<> using delegates

Posted on 2008-10-22
2
186 Views
Last Modified: 2008-10-22
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); });
0
Comment
Question by:eshurak
2 Comments
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 500 total points
ID: 22779163
you have to do it as described in the following EE question
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CSharp/Q_23593154.html
0
 
LVL 3

Author Comment

by:eshurak
ID: 22781607
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

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question