开发者

Get Post object by page

I tried to get certain amount of Post objects per page (like 10) and I tried that using extension methods

  int _start = _page * _listItemsPerPage;
  int _end = (_page + 1) * _listItemsPerPage;

  if (Posts.Count > _end)
       return  (Posts.Skip(_start).Take(_end - _start)) as List<Post>;
  else
       return  (Posts.Skip(_start).Take(Posts.Count - _start)) as List<Post>;

But I've done something wrong because It allways returns null . 开发者_运维问答Aditional info:

  • Posts is List< Post > Type, collection of dummie data
  • _page - page number
  • _listItemsPerPage - how many items are needed to be displayed
  • _start - starting index
  • _end - ending index
  • I've done prior exception check


The calls to Skip and Take return an IEnumerable<Post>, not a List<Post>, so converting to a List<Post> with as List<Post> fails and returns null.

Either add call to AsList(), or just return the IEnumerable<Post>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜