Answer:
Use the Repeat function of Enumerable class.
Enumerable class belongs to System.Linq namespace
int[] b = Enumerable.Repeat(45, 5).ToArray();
45: initial value
5: number of times the initial value should repeat.
foreach (var z in b)
{
Console.WriteLine(z);
}
Asked In: Many Interviews |
Alert Moderator