
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- Java Program to Compare Elements in a Collection
- Golang Program to Remove Repeated Elements From an Array
- Java Program to Shuffle the Elements of a Collection
- How to return a string repeated N number of times in C#?
- C program to count a letter repeated in a sentence.
- C# Program to return specified number of elements from the beginning of a sequence
- How to retain elements from a Collection in another Collection
- C++ Program to create a function with arguments and a return value
- Retrieving Elements from Collection in C#
- C++ program to find Second most repeated word in a sequence
- How to remove all elements from a Collection in another Collection
- Java Program to append all elements of other Collection to ArrayList
- Find maximum array sum after making all elements same with repeated subtraction in C++
- C++ Program to create a function with arguments but without a return value
- Copying the Collection elements to an array in C#

Advertisements