Solved

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

Posted on 2011-09-30
5
1,028 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 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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