All, I have the following class structure
public class Foo : IComparable<Foo>
{
public List<Bar> Bars;
}
public class Bar : IComparable<Bar>
{
public List<Con> Cons;
}
public class Con : IComparable<Con>
{
...
}
I know how to remove object from a list
authorsList.RemoveAll(x => x.FirstName == "Bob");
But how, for my class above, do I remove a List<Con>
called badConList
, from my base object Foo
? Explicitly, the class hierarchy is populated like
Foo foo = new Foo();
foo.Bars = new List<Bar>() { /* Some Bar list */ };
foreach (Bar bar in foo.Bars)
bar.Cons = new List<Con>() { /* Some Con list */ };
// Now a bad Con list.
List<Con> badCons = new List() { /* Some bad Con list */ };
How do I remove the badCons
from foo
for each Bar
using LINQ?
Thanks for your time.
Ps. LINQ may not be the quickest method here; a simple loop might be (which is what LINQ will be doing under the hood anyway). Can you comment on this also?