Calculates the union list of and and returns it. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

Calculates the union list of and and returns it.

Demo Code

/*//from  w w w.j a  v a 2s  .  c  om
    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>
    /// Calculates the union list of <paramref name="c1"/> and <paramref name="c2"/> and returns it. The elements
    /// of the two given enumerations of elements will all be added, first the elements of <paramref name="c1"/>,
    /// then the elements of <paramref name="c2"/>.
    /// If the type parameters of the collections differ, the collection with the more general element type
    /// must be used at the second position.
    /// </summary>
    /// <remarks>
    /// This method executes in O(sizeof(c1) + sizeof(c2)).
    /// </remarks>
    /// <typeparam name="S">Element type of the first source collection. May be more specific than
    /// the type parameter of the second collection.</typeparam>
    /// <typeparam name="T">Element type of the second source collection and the result collection.
    /// May be more general than the type parameter of the first collection <see cref="S"/>.</typeparam>
    /// <param name="c1">First source collection.</param>
    /// <param name="c2">Second source collection</param>
    /// <returns>Union set of <paramref name="c1"/> and <paramref name="c2"/>.</returns>
    public static IList<T> UnionList<S, T>(IEnumerable<S> c1, IEnumerable<T> c2) where S: T
    {
      IList<T> result = new List<T>();
      AddAll(result, c1);
      AddAll(result, c2);
      return result;
    }
}

Related Tutorials