Count similar adjacent items in List<string>
问题 I'm trying to find similar adjacent items in List and count its number, e.g.: List<string> list = new List<string> {"a", "a", "b", "d", "c", "c"}; Desired Output: a = 2, c = 2 What I've done is use for loop to iterate over each element of the list and to see whether it has similar adjacent element, but understandably it gives ArgumentOutOfRangeException() because I don't know how to keep track of the position of the iterator so that it doesn't go out of bounds. Here's what I've done: for (int