What is the method for adding duplicate values in C#?
In C#, you can add the same value using the following method:
- Create a List collection and then repeatedly add the same value using the Add() method.
List<int> numbers = new List<int>();
for (int i = 0; i < 5; i++)
{
numbers.Add(10);
}
- To create an array with the same value duplicated, you can use the static method Repeat() from the Array class.
int[] numbers = Enumerable.Repeat(10, 5).ToArray();
This way, you can add the same value to a set or array.