Home  >  Article  >  Backend Development  >  Enumerable.Repeat method in C#

Enumerable.Repeat method in C#

王林
王林forward
2023-08-28 21:33:021184browse

C# 中的 Enumerable.Repeat 方法

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

It returns a collection containing duplicate elements in C#.

First, set the elements to be repeated and the number of repetitions.

For example, let’s see how to repeat the number 10 five times−

Enumerable.Repeat(10, 5);

Here is the complete example−

Example

Demonstration

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

The above is the detailed content of Enumerable.Repeat method in C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete