Solved

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

Posted on 2011-09-30
5
984 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

10 Experts available now in Live!

Get 1:1 Help Now