我有一个IEnumerable<KeyedList<int, PictureItem>>。我想要的是我得到一个新的IEnumerable<KeyedList<int, PictureItem>>,其中只选择了每个KeyedList中的前5个条目。目前,我得到了KeyedList中的每一项。
更新:
public IEnumerable<KeyedList<int, PictureItem>> GetFirstSixImages(IEnumerable<KeyedList<int, PictureItem>> pictures)
{
var list = (from t in pictures
select t.Item).Take(5);
return list;
}这是我用的方法
发布于 2014-05-07 08:44:45
您希望对所有项执行一些操作,因此应该使用Select函数。我不知道KeyedList,因此我不知道如何用一些新项来构造一个新的KeyedList。
items.Select(keyedList => keyedList.Take(5));条件是keyedList是IEnumerable。
只是猜测,可能是这样的:
items.Select(keyedList => new KeyedList<int, PictureItem>(keyedList.Take(5)));正确的答案是(见下面的评论)
items.Select(keyedList => new KeyedList<int, PictureItem>(keyedList.Key,keyedList.Take(5)))发布于 2014-05-07 08:39:56
你试过服用了吗?
在System.Linq命名空间中包含了
希望这就足够了。
https://stackoverflow.com/questions/23512719
复制相似问题