If I have a list of booleans, how do I convert into into a list (or any other IEnnumerable<int>
) of integers where each integer represents the length of each string of booleans using LINQ?
For example {true, true, false, false, true, true, true}
would become {2, 3}
as the first run of true
s is 2 long, and the second is 3 long. Or must I go back to for and foreach loops?
I am not interested in the number of false values, they are only important because they separate runs of true values.
So {true, true, true, false, true, true, true, true, false, false, true, true, true}
would become {3, 4, 3}