抓取List< Item>的一部分按开始和结束索引 [英] Grabbing a part of the List<Item> by start and end indices

查看:83
本文介绍了抓取List< Item>的一部分按开始和结束索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能吗?

例如,如果我有

List<Item> myList = new List<Item>;

//added 100 of Items to myList

//then I want to grab items at indices 50 - 60

List<Item> myNewList = myList.?

我该如何不遍历myList? 谢谢.

How do I do that w/o looping through myList? Thank you.

推荐答案

List.GetRange是一种检索这些项目的方法. http://msdn.microsoft.com/en-us/library/21k0e39c.aspx

There is a method that retrieves these items, List.GetRange. http://msdn.microsoft.com/en-us/library/21k0e39c.aspx

List<Item> myList = new List<Item>;
myList.GetRange(50, 10); // Retrieves 10 items starting with index #50

这篇关于抓取List&lt; Item&gt;的一部分按开始和结束索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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