---
title: "Give an example of the LINQ Repeat Method."  
description: "Give an example of the LINQ Repeat Method."  
author: "Ethan Karla"  
published: 2021-09-24  
updated: 2021-09-24  
canonical: https://www.mindstick.com/forum/156775/give-an-example-of-the-linq-repeat-method  
category: "linq"  
tags: ["c#", "ado.net", "linq"]  
reading_time: 1 minute  

---

# Give an example of the LINQ Repeat Method.

Give an example of the [LINQ](https://www.mindstick.com/articles/12007/language-integrated-query-linq-queries) Repeat Method.

## Replies

### Reply by Ravi Vishwakarma

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
```

\


---

Original Source: https://www.mindstick.com/forum/156775/give-an-example-of-the-linq-repeat-method

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
