Adds the elements of the specified collection to the specified generic IList. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

Adds the elements of the specified collection to the specified generic IList.

Demo Code

// Permission is hereby granted, free of charge, to any person
using System.Globalization;
using System.Linq;
using System.Collections;
using System.Text;
using System.Reflection;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System;/*from  w  w w.  j  a  v  a 2 s  . co m*/

public class Main{
    public static void AddRange(this IList initial, IEnumerable collection)
    {
      ValidationUtils.ArgumentNotNull(initial, "initial");

      ListWrapper<object> wrapper = new ListWrapper<object>(initial);
      wrapper.AddRange(collection.Cast<object>());
    }
        /// <summary>
    /// Adds the elements of the specified collection to the specified generic IList.
    /// </summary>
    /// <param name="initial">The list to add to.</param>
    /// <param name="collection">The collection of elements to add.</param>
    public static void AddRange<T>(this IList<T> initial, IEnumerable<T> collection)
    {
      if (initial == null)
        throw new ArgumentNullException("initial");

      if (collection == null)
        return;

      foreach (T value in collection)
      {
        initial.Add(value);
      }
    }
}

Related Tutorials