The Repeat method is used to generate a collection or list with the same number as repeated times based on specified index values.
Syntax
Enumerable.Repeat<int>(start, times);
Example
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
IEnumerable<int> range = Enumerable.Repeat<int>(50,10);
long sum = range.Aggregate((a,b) => a+b);
Console.WriteLine('List ');
range.ToList().ForEach(item => Console.Write('{0}, ',item));
Console.WriteLine('\nSum : '+sum);
}
public static bool IsPrime(int num){
for(int i=2;i<Math.Sqrt(num);i++)
if(num % i ==0 )
return false;
return true;
}
}
Output
List
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
Sum : 500
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
The Repeat method is used to generate a collection or list with the same number as repeated times based on specified index values.
Syntax
Example
Output