Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

861 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now