C# Enumerable Repeat
Description
Generates a sequence that contains one repeated value.
Syntax
public static IEnumerable<TResult> Repeat<TResult>(
TResult element,
int count
)
Parameters
TResult
- The type of the value to be repeated in the result sequence.element
- The value to be repeated.count
- The number of times to repeat the value in the generated sequence.
Example
The following code example demonstrates how to use Repeat to generate a sequence of a repeated value.
/*www.j av a2 s .c o m*/
using System;
using System.Linq;
using System.Collections.Generic;
public class MainClass{
public static void Main(String[] argv){
IEnumerable<string> strings = Enumerable.Repeat("java2s.com", 15);
foreach (String str in strings)
{
Console.WriteLine(str);
}
}
}
The code above generates the following result.