SuperLinq SuperLinq
SuperLinq SuperLinq
DocFX + Singulink = ♥

Search Results for

    Method Repeat

    | Edit this page

    Repeat<TResult>(TResult)

    Generates a sequence by repeating the given value infinitely.

    Declaration
    public static IEnumerable<TResult> Repeat<TResult>(TResult value)
    Parameters
    Type Name Description
    TResult value

    Value to repeat in the resulting sequence.

    Returns
    Type Description
    IEnumerable<TResult>

    Sequence repeating the given value infinitely.

    Type Parameters
    Name Description
    TResult

    Result sequence element type.

    Examples

    The following code example demonstrates how to repeat a value using Repeat.

    // Repeat a value indefinitely
    var result = SuperEnumerable
        .Repeat(1)
        .Take(10);
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // This code produces the following output:
    // [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
    
    | Edit this page

    Repeat<TSource>(IEnumerable<TSource>)

    Repeats and concatenates the source sequence infinitely.

    Declaration
    public static IEnumerable<TSource> Repeat<TSource>(this IEnumerable<TSource> source)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    Source sequence.

    Returns
    Type Description
    IEnumerable<TSource>

    Sequence obtained by concatenating the source sequence to itself infinitely.

    Type Parameters
    Name Description
    TSource

    Source sequence element type.

    Remarks

    This operator uses deferred execution and streams its result. The source sequence is cached as the returned IEnumerable<T> is enumerated. When source has completed, the values from source will be returned again indefinitely.

    The cache is maintained separately for each IEnumerator<T> generated from the returned IEnumerable<T>.

    Examples

    The following code example demonstrates how to repeat a value using Repeat.

    var sequence = Enumerable.Range(1, 3);
    
    // Repeat a sequence indefinitely
    var result = sequence
        .Repeat()
        .Take(10);
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // This code produces the following output:
    // [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source is null.

    | Edit this page

    Repeat<TSource>(IEnumerable<TSource>, int)

    Repeats and concatenates the source sequence the given number of times.

    Declaration
    public static IEnumerable<TSource> Repeat<TSource>(this IEnumerable<TSource> source, int count)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    Source sequence.

    int count

    Number of times to repeat the source sequence.

    Returns
    Type Description
    IEnumerable<TSource>

    Sequence obtained by concatenating the source sequence to itself the specified number of times.

    Type Parameters
    Name Description
    TSource

    Source sequence element type.

    Remarks

    This operator uses deferred execution and streams its result. The source sequence is cached as the returned IEnumerable<T> is enumerated. When source has completed, the values from source will be returned again count times.

    The cache is maintained separately for each IEnumerator<T> generated from the returned IEnumerable<T>.

    Examples

    The following code example demonstrates how to repeat a value using Repeat.

    var sequence = Enumerable.Range(1, 3);
    
    // Repeat a sequence
    var result = sequence
        .Repeat(3);
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // This code produces the following output:
    // [1, 2, 3, 1, 2, 3, 1, 2, 3]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source is null.

    ArgumentOutOfRangeException

    count is less than or equal to 0.

    © SuperLinq Authors. All rights reserved.