Remove All from ObservableCollection by predicate - CSharp System.Collections.ObjectModel

CSharp examples for System.Collections.ObjectModel:ObservableCollection

Description

Remove All from ObservableCollection by predicate

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.ComponentModel;
using System.Collections.Specialized;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections;
using System;//from  ww w. j  a  v a 2  s .  co m

public class Main{
        public static void RemoveAll<T>( this ObservableCollection<T> list, Func<T,bool> match  ) where T:class
        {
            var removeItem = list.With(x => list)
                .With(x => list.FirstOrDefault(match));
                
            if (removeItem != null)
                list.Remove(removeItem);
        }
}

Related Tutorials