![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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