这可能吗?
例如,如果我有
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,我该怎么做?谢谢你。
有一个方法可以检索这些项目,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
var myNewList = myList.Skip(50).Take(10);
http://msdn.microsoft.com/en-us/library/bb503062.aspx
http://msdn.microsoft.com/en-us/library/bb357513.aspx
myList.Skip(50).Take(10)
关于什么:
List<string> myList = new List<string>();
//added 100 of Items to myList
for (int i=0; i<100; ++i)
{
myList.Add("blablabla");
}
//then I want to grab items at indices 50 - 60
// Note: 50 - 60 inclusivly are actually 11 items
List<string> myNewList = myList.GetRange(50, 11);