Use a for loop instead. You should avoid setting values while iterating with a foreach.
for
foreach
for (int i = 0; i < list.Count; i++) { if (condition) list[i] = new(); }
I cannot use a for loop here.