Can I use LINQ to retrieve only “on change” values?

前端 未结 5 926
死守一世寂寞
死守一世寂寞 2021-01-22 20:36

What I\'d like to be able to do is construct a LINQ query that retrieved me a few values from some DataRows when one of the fields changes. Here\'s a contrived example to illus

5条回答
  •  無奈伤痛
    2021-01-22 21:24

    You could useMorelinq's GroupAdjacent() extension method

    GroupAdjacent: Groups the adjacent elements of a sequence according to a specified key selector function...This method has 4 overloads.

    You would use it like this with the result selector overload to lose the IGrouping key:-

    var weatherStuff = ds.Tables[0].AsEnumerable().GroupAdjacent(w => w.Field("Observation"), (_, val) => val.Select(v => v));
    

    This is a very popular extension to default Linq methods, with more than 1M downloads on Nuget (compared to MS's own Ix.net with ~40k downloads at time of writing)

提交回复
热议问题