break up array into little arrays

前端 未结 6 794
南方客
南方客 2021-01-20 06:03

i am sending out email to a list of people. I have the list of recipients in array but the list can get up to 500 people. There is a limitation on the number of recipients

6条回答
  •  Happy的楠姐
    2021-01-20 06:31

    You could use the Batch operation from MoreLINQ:

    Person[] array = ...;
    
    var arrays = list.Batch(50).Select(x = x.ToArray());
    
    foreach (Person[] shorterArray in arrays)
    {
        ...
    }
    

    (If you're happy with IEnumerable instead of arrays, you don't need the Select call of course.)

提交回复
热议问题