How can we create an array with non-default value in C#?

 Posted by Ddd on 2/15/2011 | Category: C# Interview questions | Views: 28608 | Points: 40

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)

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response