You could create an extension method to initialize an array, for example:
public static void InitAll<T>(this T[] array, T value)
{
for (int i = 0; i < array.Length; i++)
{
array[i] = value;
}
}
and use it as follows:
bool[] buffer = new bool[128];
buffer.InitAll(true);
Edit:
To address any concerns that this isn't useful for reference types, it's a simple matter to extend this concept. For example, you could add an overload
public static void InitAll<T>(this T[] array, Func<int, T> initializer)
{
for (int i = 0; i < array.Length; i++)
{
array[i] = initializer.Invoke(i);
}
}
Foo[] foos = new Foo[5];
foos.InitAll(_ => new Foo());
//or
foos.InitAll(i => new Foo(i));
This will create 5 new instances of Foo and assign them to the foos array.