You can also make it a little more general:
public void RemoveChildren( Predicate<Child> match ) { _parentDetail.RemoveAll (match); }
Then you can use it as follows:
Parent p = new Parent(); p.RemoveAll (x => x.Text == null || String.IsNullOrEmpty(x.Text.TextWithHtml));
I would add an additional property to ParentDetail: IsEmpty
public class ParentDetail { public HtmlText Text {get; set;} public bool IsEmpty { return this.Text == null || String.IsNullOrEmpty(this.Text.TextWithHtml); } }
Then your code can be simplified as follows:
Parent p = new Parent(); p.RemoveAll (x => x.IsEmpty);
Marc's answer is explicitly (which I like), but if you want more flexibility, using the Func argument is more flexible.
source share