Home > Backend Development > C#.Net Tutorial > Enumerable.Repeat method in C#

Enumerable.Repeat method in C#

王林
Release: 2023-08-28 21:33:02
forward
1262 people have browsed it

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);
Copy after login

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);
      }
   }
}
Copy after login

Output

10
10
10
10
10
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template