I know in python you can do something like myList[1:20]
but is there anything similar in C#?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
sans LINQ quicky...
You can use
List<T>.GetRange()
:From MSDN:
This might be helpful for efficiency, if you really want to truncate the list, not make a copy. While the python example makes a copy, the original question really was about truncating the list.
Given a List<> object "list" and you want the 1st through 20th elements
This does it in place. This is still O(n) as the references to each object must be removed, but should be a little faster than any other method.