我如何使用Linq用于寻呼泛型集合? [英] How do I use Linq for paging a generic collection?

查看:156
本文介绍了我如何使用Linq用于寻呼泛型集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个System.Generic.Collections.List(中MyCustomClass)类型的对象。

I've got a System.Generic.Collections.List(Of MyCustomClass) type object.

由于整数varaibles页面大小和页面编号,MyCustomClass对象,我怎么能只查询任何一个网页?

Given integer varaibles pagesize and pagenumber, how can I query only any single page of MyCustomClass objects?

推荐答案

如果你有你的LINQ查询包含所有要显示的行,这code,可以用:

If you have your linq-query that contains all the rows you want to display, this code can be used:

var pageNum = 3;
var pageSize = 20;
query = query.Skip((pageNum - 1) * pageSize).Take(pageSize);

您还可以在对象上进行扩展方法,能够写出

You can also make an extension method on the object to be able to write

query.Page(2,50)

要拿到第50条记录第2页。如果这是要你想要的,信息是对的固体code博客。

to get the first 50 records of page 2. If that is want you want, the information is on the solid code blog.

这篇关于我如何使用Linq用于寻呼泛型集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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