LINQ的选择5个项目每个迭代 [英] Linq Select 5 items per Iteration
本文介绍了LINQ的选择5个项目每个迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Linq的选择5每次项目基于我们枚举
我们的列表例如的thelist
的 100项
想通过列表和在每个迭代中选择5项
样code,这是我们要改变到我们期望的结果是:
的thelist = dt.AsEnumerable()
。选择(行=>新建CustItem
{
NAME = row.Field<串GT(TNAME),
标题= row.Field<串GT(TTITLE),
})了ToList()。
我们应该选择的5个项目的循环和过程中的每一次迭代,或将它传递给我们的其他方式:
是这样的:
的for(int i = 0; I< 20;我++)
我想使用的 LINQ选择
语句我
枚举,并作出多样性,使边界我们新的结果集。
解决方案
的for(int i = 0; I< 20;我++)
{
VAR fiveitems = theList.Skip(我* 5)。取(5);
}
Linq Select 5 items each time based on our enumerator
Our List e.g "theList"
has 100 items,
Want to go through the list and Select 5 items in each iterations,
Sample Code, which we want to change this into our desired result :
theList = dt.AsEnumerable()
.Select(row => new CustItem
{
Name = row.Field<string>("tName"),
Title = row.Field<string>("tTitle"),
}).ToList();
We should Iterate it within a loop and process on the selected 5 items each time, or pass it to our other methods :
something like it :
for (int i=0; i < 20 ; i++)
I want to use "i"
enumerator on the linq select
statement and make a multiplicity to make the boundaries of our new resultset.
解决方案
for (int i=0; i < 20 ; i++)
{
var fiveitems = theList.Skip(i*5).Take(5);
}
这篇关于LINQ的选择5个项目每个迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文