分手数组的数组不大 [英] break up array into little arrays

查看:146
本文介绍了分手数组的数组不大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发送邮件的电子邮件以人的名单。我有收件人列表中的数组,但列表中可以得到高达500人。这里对于我的邮件服务器在一次(50个收件人)

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 that my mail server sends out at once (50 recipients)

因此​​,如果该列表> 50我需要打破它在不同的邮件。

so if the list is > 50 i need to break it up in to different mails.

什么是采取一个阵列,并把它分解成50

What is the best way to take one array and break it up into arrays of 50

例如:

如果数组是120长,我希望3阵列退换,50,另外有50和20个第三

if array is 120 long, i would expect 3 arrays returned, one with 50, another with 50 and a third with 20.

推荐答案

您可以使用的

You could use the Batch operation from MoreLINQ:

Person[] array = ...;

var arrays = list.Batch(50).Select(x = x.ToArray());

foreach (Person[] shorterArray in arrays)
{
    ...
}

(如果你很高兴与的IEnumerable<人> 代替数组,你不需要选择当然电话。)

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

这篇关于分手数组的数组不大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆