Is there a \"nice\" way to eliminate consecutive duplicates of list elements?
Example:
[\"red\"; \"red\"; \"blue\"; \"green
Taking @Simon Bartlett's clean approach and improving upon it, you could also perform this generically.
public static IEnumerable UniqueInOrder(IEnumerable iterable)
{
var returnList = new List();
foreach (var item in iterable)
{
if (returnList.Count == 0 || !returnList.Last().Equals(item))
returnList.Add(item);
}
return returnList;
}