I have an IEnumerable and I want to get a new IEnumerable containing every nth element.
Can this be done in Linq?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just figured it out myself…
The
IEnumerable<T>.Where()method has an overload that takes the index of the current element – just what the doctor ordered.This would return
Update: In order to cover both my use case and Dan Tao’s suggestion, let’s also specify what the first returned element should be:
…would return