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

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

[{'answer_id': 21389, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 6, 'selected': True, 'text': '<p>If you have your linq-query that contains all the rows you want to display, this code can be used:</p>\n\n<pre><code>var pageNum = 3;\nvar pageSize = 20;\nquery = query.Skip((pageNum - 1) * pageSize).Take(pageSize);\n</code></pre>\n\n<p>You can also make an extension method on the object to be able to write</p>\n\n<pre><code>query.Page(2,50)\n</code></pre>\n\n<p>to get the first 50 records of page 2. If that is want you want, the information is on the <a href="http://solidcoding.blogspot.com/2007/11/paging-with-linq.html" rel="noreferrer">solid code blog.</a></p>\n'}, {'answer_id': 442698, 'author': 'CraftyFella', 'author_id': 30317, 'author_profile': 'https://Stackoverflow.com/users/30317', 'pm_score': 3, 'selected': False, 'text': '<p>Hi There is a wicked thing called PagedList which i got when watching a Rob Conery Screen Cast. </p>\n\n<p><a href="http://blog.wekeroad.com/2007/12/10/aspnet-mvc-pagedlistt/" rel="noreferrer">http://blog.wekeroad.com/2007/12/10/aspnet-mvc-pagedlistt/</a></p>\n\n<p>It has all the Skip and Take stuff built in.</p>\n\n<p>All you do is call</p>\n\n<pre><code>var query = from item in DB.Table\nwhere item.Field == 1\norderby item.Field2\nselect item;\n\nPagedList&lt;MyType&gt; pagedList = query.ToPagedList(pageIndex, pageSize);\n</code></pre>\n\n<p>Hope it helps.. I\'m using it now and it works ok for linq to entities. With Linq to entities you have to perform an Orderby before you can use Skip and Take.</p>\n'}]
['https://Stackoverflow.com/questions/21184', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/83/']