I have a list which contains 91 items in it. I currently loop over and write each line to a text file using StreamWriter
. I want to divide the list by 3 so after 30 items I want to insert a blank line. So far I have
foreach (var item in textList)
{
//write to file
counter++;
if (counter == totalItems / 3)
{
await sw.WriteLineAsync(Environment.NewLine);
}
}
but it only works for the first 30 items. Please note the list can contain any number of items but this particular one contains 91. However I will always have to divide into 3.