SelectMany.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Collections.Generic;
  5. namespace System.Linq
  6. {
  7. public static partial class EnumerableEx
  8. {
  9. /// <summary>
  10. /// Projects each element of a sequence to an given sequence and flattens the resulting sequences into one sequence.
  11. /// </summary>
  12. /// <typeparam name="TSource">First source sequence element type.</typeparam>
  13. /// <typeparam name="TOther">Second source sequence element type.</typeparam>
  14. /// <param name="source">A sequence of values to project.</param>
  15. /// <param name="other">Inner sequence each source sequence element is projected onto.</param>
  16. /// <returns>Sequence flattening the sequences that result from projecting elements in the source sequence.</returns>
  17. public static IEnumerable<TOther> SelectMany<TSource, TOther>(this IEnumerable<TSource> source, IEnumerable<TOther> other)
  18. {
  19. if (source == null)
  20. {
  21. throw new ArgumentNullException(nameof(source));
  22. }
  23. if (other == null)
  24. {
  25. throw new ArgumentNullException(nameof(other));
  26. }
  27. return source.SelectMany(_ => other);
  28. }
  29. }
  30. }