SelectMany.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132
  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;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. namespace System.Linq
  9. {
  10. public static partial class EnumerableEx
  11. {
  12. /// <summary>
  13. /// Projects each element of a sequence to an given sequence and flattens the resulting sequences into one sequence.
  14. /// </summary>
  15. /// <typeparam name="TSource">First source sequence element type.</typeparam>
  16. /// <typeparam name="TOther">Second source sequence element type.</typeparam>
  17. /// <param name="source">A sequence of values to project.</param>
  18. /// <param name="other">Inner sequence each source sequenec element is projected onto.</param>
  19. /// <returns>Sequence flattening the sequences that result from projecting elements in the source sequence.</returns>
  20. public static IEnumerable<TOther> SelectMany<TSource, TOther>(this IEnumerable<TSource> source, IEnumerable<TOther> other)
  21. {
  22. if (source == null)
  23. throw new ArgumentNullException(nameof(source));
  24. if (other == null)
  25. throw new ArgumentNullException(nameof(other));
  26. return source.SelectMany(_ => other);
  27. }
  28. }
  29. }