T
Tony Johansson
Hello!
Below I have a collection of 26 Test object.
Each Test class has three fields named Parameter, Value and WorksheetRowID
What I want it to create a LINQ query that counts how many group of the same
parameter and value that
exist in sequence. In my example here I have 2 groups with this group in
sequence
T 4 49
N 3 49
NCP 2 49
Then I have three groups with this group in sequence
T 6 112
N 3 112
CACP 5 112
CSCP 10 112
Then I have only 1 group in sequence appearance
T 10 175
NCP 0 175
Finally I have two groups in sequence that look like this
T 4 180
N 3 180
NCP 2 180
So my linq query should return the following result 2,3,1,2.
NOTE: I'm not allowed to group this group
T 4 180
N 3 180
NCP 2 180
together with these because there are different groups in between.
T 4 49
N 3 49
NCP 2 49
T 4 70
N 3 70
NCP 2 70
One solution is to use a foreach and looping through the whole collection
and compare if next
group is the same as the previous if so increment a counter and so on.
But I just want to find out if I can create a LINQ query in some way
that solve this in a much more elegant way.
//Tony
Parameter Value WorksheetRowID
T 4 49
N 3 49
NCP 2 49
T 4 70
N 3 70
NCP 2 70
T 6 112
N 3 112
CACP 5 112
CSCP 10 112
T 6 133
N 3 133
CACP 5 133
CSCP 10 133
T 6 154
N 3 154
CACP 5 154
CSCP 10 154
T 10 175
NCP 0 175
T 4 180
N 3 180
NCP 2 180
T 4 185
N 3 185
NCP 2 185
Below I have a collection of 26 Test object.
Each Test class has three fields named Parameter, Value and WorksheetRowID
What I want it to create a LINQ query that counts how many group of the same
parameter and value that
exist in sequence. In my example here I have 2 groups with this group in
sequence
T 4 49
N 3 49
NCP 2 49
Then I have three groups with this group in sequence
T 6 112
N 3 112
CACP 5 112
CSCP 10 112
Then I have only 1 group in sequence appearance
T 10 175
NCP 0 175
Finally I have two groups in sequence that look like this
T 4 180
N 3 180
NCP 2 180
So my linq query should return the following result 2,3,1,2.
NOTE: I'm not allowed to group this group
T 4 180
N 3 180
NCP 2 180
together with these because there are different groups in between.
T 4 49
N 3 49
NCP 2 49
T 4 70
N 3 70
NCP 2 70
One solution is to use a foreach and looping through the whole collection
and compare if next
group is the same as the previous if so increment a counter and so on.
But I just want to find out if I can create a LINQ query in some way
that solve this in a much more elegant way.
//Tony
Parameter Value WorksheetRowID
T 4 49
N 3 49
NCP 2 49
T 4 70
N 3 70
NCP 2 70
T 6 112
N 3 112
CACP 5 112
CSCP 10 112
T 6 133
N 3 133
CACP 5 133
CSCP 10 133
T 6 154
N 3 154
CACP 5 154
CSCP 10 154
T 10 175
NCP 0 175
T 4 180
N 3 180
NCP 2 180
T 4 185
N 3 185
NCP 2 185