下载数据反向循环c#
Download data reverse Loop c#
我只想从 Maibox 下载我的电子邮件 100。但我正在尝试从下到上循环下载数据。我想从上层下载数据到下层
// for (int i = count; i >=0 && i <= 100; i--) /// <--- It works but if i have e-mails more than 100 not working.
for (int i = 1; i <= count && i <= 100 ; i++) // <-- this download from old data to new.
OpenPop.Mime.Message message = client.GetMessage(i);
OpenPop.Mime.MessagePart html = message.FindFirstHtmlVersion();
if (html != null)
{
htmlContained = html.GetBodyAsText();
}
这个怎么样?
for (int i = count; i > count - 100 && i >= 0; i--)
这是您的评论
// for (int i = count; i >=0 && i <= 100; i--) /// <--- It works but if i have e-mails more than 100 not working.
现在让我帮你解释一下你自己的代码。
i = 计数包含的值
这个循环将 运行 而
我大于或等于 0 且小于或等于硬编码的 100;
我会在每个循环周期中降低 1。
现在,这 100 部分。在这里你限制自己不能看到超过100个。如果你去掉它,你就不会限制自己只能看到100个以下的那些。
所以只写
for (int i = count; i >=0; i--)
如果您需要 100 个限制,请使用您的旧查询。
如果你需要它以相反的顺序只否定表达式
for (int i = 0; i < count; i++)
与100限制相同:
int limit = 100;
for (int i = 0; i < limit; i++)
此外,如果您需要特定顺序,只需使用 linq 查询表达式即可。
因为我不知道你的代码,所以我只是把它编出来,这样你就可以调整它或使用 google 和 msdn 来调整它以满足你的需要。
var newEmailList = emails.OrderBy(email.whateverYouNeed).Take(100)
要么
var newEmailListDesc = emails.OrderByDescending(email.whateverYouNeed).Take(100)
然后你可以使用foreach来快速处理你的任务。
我只想从 Maibox 下载我的电子邮件 100。但我正在尝试从下到上循环下载数据。我想从上层下载数据到下层
// for (int i = count; i >=0 && i <= 100; i--) /// <--- It works but if i have e-mails more than 100 not working.
for (int i = 1; i <= count && i <= 100 ; i++) // <-- this download from old data to new.
OpenPop.Mime.Message message = client.GetMessage(i);
OpenPop.Mime.MessagePart html = message.FindFirstHtmlVersion();
if (html != null)
{
htmlContained = html.GetBodyAsText();
}
这个怎么样?
for (int i = count; i > count - 100 && i >= 0; i--)
这是您的评论
// for (int i = count; i >=0 && i <= 100; i--) /// <--- It works but if i have e-mails more than 100 not working.
现在让我帮你解释一下你自己的代码。 i = 计数包含的值
这个循环将 运行 而 我大于或等于 0 且小于或等于硬编码的 100; 我会在每个循环周期中降低 1。
现在,这 100 部分。在这里你限制自己不能看到超过100个。如果你去掉它,你就不会限制自己只能看到100个以下的那些。
所以只写
for (int i = count; i >=0; i--)
如果您需要 100 个限制,请使用您的旧查询。
如果你需要它以相反的顺序只否定表达式
for (int i = 0; i < count; i++)
与100限制相同:
int limit = 100;
for (int i = 0; i < limit; i++)
此外,如果您需要特定顺序,只需使用 linq 查询表达式即可。
因为我不知道你的代码,所以我只是把它编出来,这样你就可以调整它或使用 google 和 msdn 来调整它以满足你的需要。
var newEmailList = emails.OrderBy(email.whateverYouNeed).Take(100)
要么
var newEmailListDesc = emails.OrderByDescending(email.whateverYouNeed).Take(100)
然后你可以使用foreach来快速处理你的任务。