Check out example codes for "Collection was modified; enumeration operation might not execute. datatable c#". It will help you in understanding the concepts better.

Code Example 1

using CentroidsList = System.Collection.Generic.List<...>; //put the type of the element of newSpectrum.PeakCentroids


CentroidsList list = new CentroidsList();
foreach (var element in newSpectrum.PeakCentroids)
   if (SomeCondition(element))
foreach (var element in list)

Learn ReactJs, React Native from