CSharp examples for System.Collections.Generic:IEnumerable
Calculates the union set of IEnumerable and returns it.
/*// w w w .j a v a 2 s .co m 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 set of <paramref name="c1"/> and <paramref name="c2"/> and returns it. The result set /// will contain all elements of <paramref name="c1"/> and those arguements of <paramref name="c2"/> which aren't /// present in <paramref name="c1"/>. /// 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 ICollection<T> UnionSet<S, T>(IEnumerable<S> c1, IEnumerable<T> c2) where S: T { ICollection<T> result = new HashSet<T>(); AddAll(result, c1); AddAll(result, c2); return result; } }