Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C# Program to return a collection with repeated elements
To return a collection with repeated elements in C#, use Enumerable.Repeat method.
It is part of System.Linq namespace.
Let’s say you need to repeat a number twice, for that set the number and the frequency of repetition.
Enumerable.Repeat(50, 2);
Now assign it to a variable and display it.
Example
using System;
using System.Linq;
class Demo {
static void Main() {
// repeating element 50, two times
var num = Enumerable.Repeat(50, 2);
// displayig repeating elements
foreach (int ele in num) {
Console.WriteLine(ele);
}
}
}
Output
50 50
Advertisements
