blog community

Welcome to blog community Sign in | Join | Help
in Search

Browse by Tags

All Tags » C# » .NET » Sequence number
  • Selecting or filtering on the sequence number in Linq

    A few weeks ago I was writing a Linq query where I needed each items sequence number (or index) as a part of the filter expression in a Where operation. To simplify the actual problem let's say I needed to filter out only the odd items. One (wrong) way to do this would be: int i = 0; var filtered = input.Where(x => i++ % 2 == 1); This ...
    Posted to Frank Bakker (Weblog) by frankb on November 23, 2008
Powered by Community Server, by Telligent Systems