Solved

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

Posted on 2011-09-30
5
1,067 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 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