

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create an array with non-default repeated values in C#?
We can create an array with non-default values using Enumerable.Repeat(). It repeated a collection with repeated elements in C#. Firstly, set which element you want to repeat and how many times.
Example 1
class Program{ static void Main(string[] args){ var values = Enumerable.Repeat(10, 5); foreach (var item in values){ System.Console.WriteLine(item); } Console.ReadLine(); } }
Output
10 10 10 10 10
Example 2
class Program{ static void Main(string[] args){ int[] values = Enumerable.Repeat(10, 5).ToArray(); foreach (var item in values){ System.Console.WriteLine(item); } Console.ReadLine(); } }
Output
10 10 10 10 10
- Related Questions & Answers
- How to create a vector with repeated values in R?
- Mapping an array to a new array with default values in JavaScript
- JavaScript: How to filter out Non-Unique Values from an Array?
- Default array values in Java
- How to create a data frame with a column having repeated values in R?
- Convert array with duplicate values to object with number of repeated occurrences in JavaScript
- How to initialize an array in Kotlin with values?
- How to validate if an element in an array is repeated? - JavaScript
- How can we add columns with default values to an existing MySQL table?
- A shorthand array notation in C for repeated values?
- How to create a repeated values column with each value in output selected randomly in R data frame?
- Create an array class with possibly masked values and fill in the masked values in Numpy
- What are the default array values in Java?
- How to create an ordered array from values that have an order number in JavaScript?
- What are the default initialization values of elements in an array using Java?
Advertisements