I have a list in C#. Given two number - the starting position and the number of records - how can I select from the middle of a list? What kind of collection should I use?
E.g. Starting position = 10. Number of records = 20. Total number of records in list = 50. I want to get back the objects in elements 10 to 29.
Assuming you're using .NET 3.5:
using System.Linq;
list.Skip(10).Take(20)
Something like list1.Skip(10).Take(20)
should work for you
use the LINQ extension methods skip()
and take()
var myList = getList();
var middle = myList.Skip(10).Take(20);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With