Say we have a list {a, a, a, b, b, c, c }
We want to loop through the list and make some kind of change when the item value changes... for example:
prevEmployer = String.empty;
foreach(Person p in PersonList){
if(p.Employer != prevEmployer){
doSomething();
prevEmployer = p.Employer;
}
... more code
}
Is there any alternative to this? It just looks cludgy to me.
Edit: made the code more realistic to the problem at hand.