Repeat.cs 676 B

123456789101112131415161718192021
  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. using System.Diagnostics;
  6. using System.Threading.Tasks;
  7. namespace System.Linq
  8. {
  9. public static partial class AsyncEnumerable
  10. {
  11. public static IAsyncEnumerable<TResult> Repeat<TResult>(TResult element, int count)
  12. {
  13. if (count < 0)
  14. throw new ArgumentOutOfRangeException(nameof(count));
  15. return Enumerable.Repeat(element, count).ToAsyncEnumerable();
  16. }
  17. }
  18. }