Sequentially adds all elements, returned by the enumerator, to the specified collection. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:ICollection

Description

Sequentially adds all elements, returned by the enumerator, to the specified collection.

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;// w ww  . j  a v a2  s . c  o m

public class Main{
        /// <summary>
    ///   <para>Sequentially adds all elements, returned by the enumerator, to the specified collection.</para>
    /// </summary>
    /// <typeparam name="T">Type of collection's elements.</typeparam>
    /// <param name="self">Collection to which elements are added.</param>
    /// <param name="other">Elements enumerator that provide elements for addition to the collection <paramref name="self"/>.</param>
    /// <returns>Reference to the supplied collection <paramref name="self"/>.</returns>
    /// <exception cref="ArgumentNullException">If either <paramref name="self"/> or <paramref name="other"/> is a <c>null</c> reference.</exception>
    /// <seealso cref="ICollection{T}.Add(T)"/>
    public static ICollection<T> Add<T>(this ICollection<T> self, IEnumerable<T> other)
    {
      Assertion.NotNull(self);
      Assertion.NotNull(other);

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

      return self;
    }
}

Related Tutorials