I have the following class:
- Id int
- Active bool
- DateTime datetime
- Approved bool
I have the list of that class similar to this:
- Id 1 Active true Approved true
- Id 2 Active true Approved true
- Id 3 Active true Approved true
- Id 4 Active true Approved false
- Id 5 Active true Approved false
- Id 6 Active true Approved false
- Id 7 Active true Approved true
- Id 8 Active true Approved true
- Id 9 Active true Approved false
I want to get items from list group by Approved but i want grouped objects to be in this order:
- True all objects till first false.
- False all objects till next true.
- True all objects till next false.
- False all objects till next true.
Thanks in advance
Looks like you need to use TakeWhile method
http://msdn.microsoft.com/ru-ru/library/bb534804(v=vs.95).aspx
I’m not very good in LINQ but this code should work. This principle also could be extended not only for booleans, but for any type which supports IEqualityComparer