Person[] array = ...;
var arrays = list.Batch(50).Select(x = x.ToArray());
foreach (Person[] shorterArray in arrays)
{
...
}
Run Code Online (Sandbox Code Playgroud)
(如果您IEnumerable<Person>对阵列感到满意,那么您Select当然不需要通话.)
也许ArraySegment<T>适合你?你必须手动拆分它,但这在循环中并不难.
int recipient = 0;
while (recipient < recipients.Count) {
ArraySegment<string> recipientSegment = new ArraySegment<string>(recipients, recipient, Math.Min(50, recipients.Count-recipient));
// build your message here, using the recipientSegment for the names
recipient += 50;
}
Run Code Online (Sandbox Code Playgroud)