Search code examples
c#linqlistlambda

How can I get every nth item from a List<T>?


I'm using .NET 3.5 and would like to be able to obtain every *n*th item from a List. I'm not bothered as to whether it's achieved using a lambda expression or LINQ.

Edit

Looks like this question provoked quite a lot of debate (which is a good thing, right?). The main thing I've learnt is that when you think you know every way to do something (even as simple as this), think again!


Solution

  • return list.Where((x, i) => i % nStep == 0);