Group By (another question)
-
A while back I posted a question[^] and got an answer[^] that worked for that situation. However, the situation has changed (as it always does) and I am wondering if anyone can help solve this. I have an array (no longer a matrix) of items with an
Index
(int) and anIsAcceptable
flag. I want to group all items that are NOT acceptable next to each other with some items that are acceptable depending on a value used to compare to the index. For example (simple)int x = 0;
Collection = new CustomCollection()
{
new CustomObject(){Index = x++, IsAcceptable = true},
new CustomObject(){Index = x++, IsAcceptable = true},
new CustomObject(){Index = x++, IsAcceptable = false},
new CustomObject(){Index = x++, IsAcceptable = false},
new CustomObject(){Index = x++, IsAcceptable = false},
new CustomObject(){Index = x++, IsAcceptable = true},
new CustomObject(){Index = x++, IsAcceptable = true},
new CustomObject(){Index = x++, IsAcceptable = true},
new CustomObject(){Index = x++, IsAcceptable = true},
new CustomObject(){Index = x++, IsAcceptable = true},
}This would be an array of 10 elements where items with index 2,3,and 4 are flagged as not acceptable. They are to be grouped. That part can be done with the solution to my previous question. However, I want to pass in to the comparer a value. For example 1 and then Group 1--> Indecies of 1,2,3,4, and 5. Now for the complex situation that must also be handled.
int x = 0;
Collection = new CustomCollection()
{
new CustomObject(){Index = x++, IsAcceptable = true},
new CustomObject(){Index = x++, IsAcceptable = true},
new CustomObject(){Index = x++, IsAcceptable = false},
new CustomObject(){Index = x++, IsAcceptable = false},
new CustomObject(){Index = x++, IsAcceptable = false},
new CustomObject(){Index = x++, IsAcceptable = true},
new CustomObject(){Index = x++, IsAcceptable = true},
new CustomObject(){Index = x++, IsAcceptable = false},
new CustomObject(){Index = x++, IsAcceptable = true},
new CustomObject(){Index = x++, IsAcceptable = true},
}In this case the