Home > Article > Backend Development > How to create an array with non-default repeating values in C#?
We can use Enumerable.Repeat() to create an array with non-default values. it Repeat a collection containing repeated elements in C#. First, set which element you Repeat as many times as you want.
class Program{ static void Main(string[] args){ var values = Enumerable.Repeat(10, 5); foreach (var item in values){ System.Console.WriteLine(item); } Console.ReadLine(); } }
10 10 10 10 10
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(); } }
10 10 10 10 10
The above is the detailed content of How to create an array with non-default repeating values in C#?. For more information, please follow other related articles on the PHP Chinese website!