Enumerable.Repeat method in C#

ProgrammingServer Side ProgrammingCsharp

Enumerable.Repeat method is part of System.Linq namespace.

It returns a collection with repeated elements in C#.

Firstly, set which element you want to repeat and how many times.

As an example, let us see how to repeat number 10, five times −

Enumerable.Repeat(10, 5);

The following is the complete example −

Example

 Live Demo

using System;
using System.Linq;
class Demo {
   static void Main() {
      var val = Enumerable.Repeat(10, 5);
      foreach (int res in val) {
         Console.WriteLine(res);
      }
   }
}

Output

10
10
10
10
10
raja
Published on 11-Sep-2018 12:42:04
Advertisements