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

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

LVL 1
BruceAsked:
Who is Participating?
 
p_davisConnect With a Mentor Commented:
I apologize I just saw what i wanted -- it is exposed in List class

mcl.ToList().RemoveAll(x=> x.Amount > 9);
0
 
p_davisCommented:
mcl.RemoveAll(x=> x.Amount > 9);
0
 
BruceAuthor Commented:
I am using IList.  RemoveAll isn't exposed through that interface...that I can see.  (not sarcasm, I am learning this.)
0
 
BruceAuthor Commented:
Got it!

Thanks for the quick response!

The points are all yours.  :-)
0
 
p_davisCommented:
thanks, good luck
0
All Courses

From novice to tech pro — start learning today.