Enumerable.Repeat<'TResult> Method ('TResult, Int32)


Generates a sequence that contains one repeated value.

Namespace:   System.Linq
Assembly:  System.Core (in System.Core.dll)

static member Repeat<'TResult> : 
        element:'TResult *
        count:int -> IEnumerable<'TResult>


Type: TResult

The value to be repeated.

Type: System.Int32

The number of times to repeat the value in the generated sequence.

Return Value

Type: System.Collections.Generic.IEnumerable<'TResult>

An IEnumerable<'T> that contains a repeated value.

Type Parameters


The type of the value to be repeated in the result sequence.

Exception Condition

count is less than 0.

This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. The query represented by this method is not executed until the object is enumerated either by calling its GetEnumerator method directly or by using foreach in Visual C# or For Each in Visual Basic.

The following code example demonstrates how to use Repeat<'TResult> to generate a sequence of a repeated value.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top