I have 1 million elements in an array, I need to divide these elements into groups of 100, do a function and continue working on the next hundred
foreach (string value in lines)
{
filescreated++;
if (filescreated == ?????????)
{
do stuff
}
}
???? is equal to value divisible by 100
is equal to value divisable by 100
foreach (...)
{
filescreated++;
if (filescreated % 100 == 0)
{
// do stuff for the every 100th element
}
// do other stuff for every element
}
Reference: modulus (%) operator
Use this if you need to do something special for every 100th element, but you still need to process every element.
If you only need to process every 100th element, refer to Reed's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With