CSharp examples for System.Collections:ICollection
Removes all elements in the enumeration from the ICollection.
/*//from w ww .j a v a 2 s . c o m Copyright (C) 2007-2017 Team MediaPortal http://www.team-mediaportal.com This file is part of MediaPortal 2 MediaPortal 2 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. MediaPortal 2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with MediaPortal 2. If not, see <http://www.gnu.org/licenses/>. */ using System.Linq; using System.Collections.Generic; using System.Collections; using System; public class Main{ /// <summary> /// Removes all elements in the <paramref name="source"/> enumeration from the <paramref name="target"/> collection. /// </summary> /// <typeparam name="S">Type of the source elements. Needs to be equal to <see cref="T"/> or to be a /// sub type.</typeparam> /// <typeparam name="T">Target type.</typeparam> /// <param name="target">Target collection where all elements from <paramref name="source"/> will be removed.</param> /// <param name="source">Source enumeration whose elements will be removed from <paramref name="target"/>.</param> public static void RemoveAll<S, T>(ICollection<T> target, IEnumerable<S> source) where S: T { foreach (S s in source) target.Remove(s); } }