How to populate/instantiate a C# array with a single value?
Enumerable.Repeat(true, 1000000).ToArray();
Don't know of a framework method but you could write a quick helper to do it for you.
public static void Populate<T>(this T[] arr, T value ) {
for ( int i = 0; i < arr.Length;i++ ) {
arr[i] = value;
}
}
Create a new array with a thousand true
values:
var items = Enumerable.Repeat<bool>(true, 1000).ToArray(); // Or ToList(), etc.
Similarly, you can generate integer sequences:
var items = Enumerable.Range(0, 1000).ToArray(); // 0..999