Sequentially removes all elements, returned by the enumerator, from the specified collection, if it has it. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:ICollection

Description

Sequentially removes all elements, returned by the enumerator, from the specified collection, if it has it.

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from   w ww  . j  a va2 s. co  m*/

public class Main{
        /// <summary>
    ///   <para>Sequentially removes all elements, returned by the enumerator, from the specified collection, if it has it.</para>
    /// </summary>
    /// <typeparam name="T">Type of collection's elements.</typeparam>
    /// <param name="self">Collection from which elements are removed.</param>
    /// <param name="other">Elements enumerator that provider elements for removal from the collection <see cref="self"/>.</param>
    /// <exception cref="ArgumentNullException">If either <paramref name="self"/> or <paramref name="other"/> is a <c>null</c> reference.</exception>
    /// <seealso cref="ICollection{T}.Remove(T)"/>
    /// <seealso cref="Add{T}(ICollection{T}, IEnumerable{T})"/>
    public static ICollection<T> Remove<T>(this ICollection<T> self, IEnumerable<T> other)
    {
      Assertion.NotNull(self);
      Assertion.NotNull(other);

      foreach (var item in other)
      {
        self.Remove(item);
      }

      return self;
    }
}

Related Tutorials