Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I remove a group of Items from an IList?

Posted on 2011-09-30
5
Medium Priority
?
1,220 Views
Last Modified: 2013-12-16
How do I remove all items from an IList that match a certain criteria of the type that the IList contains?

See the code...

The compiler say "Cannot resolve Symbol 'Amount'"

If I change Remove statement to this: mcl.Remove(x.Amount > 9);  , it says that it cannot resolve 'x'.

Thanks!!


public class MyClass
    {
        public decimal Amount;
    }

public void MyTest()
        {
            MyClass mc = new MyClass{Amount = 10};

            IList<MyClass> mcl = new List<MyClass>();
            mcl.Add(mc);
            mcl.Remove(x => x.Amount > 9);
        }

Open in new window

0
Comment
Question by:Bruce
  • 3
  • 2
5 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 36892558
mcl.RemoveAll(x=> x.Amount > 9);
0
 
LVL 1

Author Comment

by:Bruce
ID: 36892620
I am using IList.  RemoveAll isn't exposed through that interface...that I can see.  (not sarcasm, I am learning this.)
0
 
LVL 22

Accepted Solution

by:
p_davis earned 2000 total points
ID: 36892642
I apologize I just saw what i wanted -- it is exposed in List class

mcl.ToList().RemoveAll(x=> x.Amount > 9);
0
 
LVL 1

Author Comment

by:Bruce
ID: 36892688
Got it!

Thanks for the quick response!

The points are all yours.  :-)
0
 
LVL 22

Expert Comment

by:p_davis
ID: 36892691
thanks, good luck
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

824 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