C# foreach string in array process in groups of X amout -


this question has answer here:

i trying iterate through array , process every x amount (in case 90), move go though loop until array has been exhausted. achieved if array fixed amount, sadly not.

//test range of 90 total tag collection         private void testexcelrange(string[] tagcollection)         {             string delltag = null;             int maxgroupammount = 90;             foreach(string singletag in tagcollection)             {                 //process in groups of 90 -- maxgroupammount                  if (singletag != "none")                 {                     delltag += singletag+ "|";                 }                 //after 90 process again until tagcollection complete                            }                     } 

here method splits list or array chunks of size:

public ienumerable<ienumerable<t>> getchunks<t>(ienumerable<t> elements, int size) {     var list = elements.tolist();     while (list.count > 0)     {         var chunk = list.take(size);         yield return chunk;          list = list.skip(size).tolist();     } } 

you can process array this:

private void testexcelrange(string[] tagcollection) {     string delltag = null;     int maxgroupamount = 90;     var chunks = getchunks(tagcollection, maxgroupamount);      foreach (ienumerable<string> chunk in chunks)     {         //process in groups of 90           }             } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -