Concatenates all target collections into a single collection. The items are added in order. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:ICollection

Description

Concatenates all target collections into a single collection. The items are added in order.

Demo Code

// All rights reserved.
using System.Collections.Generic;
using System.Collections;
using System;// w  w w  .  j a va  2  s .  co  m

public class Main{
        /// <summary>
      /// Concatenates all target collections into a single collection.  The items are added
      /// in order.
      /// </summary>
      /// <typeparam name="TItem"></typeparam>
      /// <param name="targets"></param>
      /// <returns></returns>
      public static List<TItem> Concat<TItem>(List<List<TItem>> targets)
      {
         var result = new List<TItem>();
         foreach (var target in targets)
         {
            result.AddRange(target);
         }
         return result;
      }
        /// <summary>
      /// Concatenates all target collections into a single collection.  The items are added
      /// in order.
      /// </summary>
      /// <param name="targets"></param>
      /// <returns></returns>
      public static ArrayList Concat(params ICollection[] targets)
      {
         var result = new ArrayList();
         foreach (var target in targets)
         {
            result.AddRange(target);
         }
         return result;
      }
        /// <summary>
      /// Concatenates all target collections into a single collection.  The items are added
      /// in order.
      /// </summary>
      /// <typeparam name="TItem"></typeparam>
      /// <param name="targets"></param>
      /// <returns></returns>
      public static List<TItem> Concat<TItem>(params IEnumerable<TItem>[] targets)
      {
         var result = new List<TItem>();
         foreach (var target in targets)
         {
            result.AddRange(target);
         }
         return result;
      }
}

Related Tutorials