IgnoreElements.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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. /// Ignores all elements in the source sequence.
  11. /// </summary>
  12. /// <typeparam name="TSource">Source sequence element type.</typeparam>
  13. /// <param name="source">Source sequence.</param>
  14. /// <returns>Source sequence without its elements.</returns>
  15. public static IEnumerable<TSource> IgnoreElements<TSource>(this IEnumerable<TSource> source)
  16. {
  17. if (source == null)
  18. throw new ArgumentNullException(nameof(source));
  19. return IgnoreElementsCore(source);
  20. }
  21. private static IEnumerable<TSource> IgnoreElementsCore<TSource>(IEnumerable<TSource> source)
  22. {
  23. foreach (var _ in source)
  24. ;
  25. yield break;
  26. }
  27. }
  28. }