Say I have the following class:
internal class ModuleScrap
{
public System.DateTime ReadTime { get; set; }
public int NetScrap { get; set; }
}
I would like a Linq query that finds for me all NetScrap values that were greater than the NetScrap value before it, based on ReadTime. So, a query that looks something like this:
MyList
.OrderBy(row => row.ReadTime)
.Where (row => row.NetScrap > [The Previous NetScrap Value])
Is such a query possible?
Yes, using
ZipandSkip(assuming .NET 4):Zipping a sequence with itself skipped one gives you pairs of consecutive elements:
If you read each column from the above, you get the pairings. From there, you just need to select each value where the second entry’s
NetScrapis greater than the first.