using System.Diagnostics;
public static void Main()
Console.WriteLine("array loop:");
Console.WriteLine("custom array:");
public static void ArrayLoopSpeedTest()
Stopwatch sw = Stopwatch.StartNew();
bool[] array = new bool[7000];
for (var i = 0; i < array.Length; i++)
Console.WriteLine(trueCount);
Console.WriteLine(sw.Elapsed);
public static void CustomArrayLoopTest()
Stopwatch sw = Stopwatch.StartNew();
CustomBoolArrayWrapper array = new CustomBoolArrayWrapper(7000);
var trueCount = array.TrueCount;
Console.WriteLine(trueCount);
Console.WriteLine(sw.Elapsed);
public class CustomBoolArrayWrapper
private readonly bool[] _internalArray;
private int _trueCount = 0;
public CustomBoolArrayWrapper(uint arraySize)
this._internalArray = new bool[arraySize];
public int TrueCount => this._trueCount;
public bool this[int index]
return this._internalArray[index];
if (this._internalArray[index] == value)
this._internalArray[index] = value;