You can do this quite easily with looping through over i
from 2 to list.Length
and check if list[i] == list[i - 1] && list[i - 1] == list[i - 2]
.
For instance, it can be written like this:
var list = new[] { 80,81,90,90,90,100,85,86,86,79,95,95,95 };
var dupes = new List<int>();
for(var i = 2; i < list.Length; i++) {
if(list[i] == list[i - 1] && list[i] == list[i - 2])
dupes.Add(list[i]);
}
[Edit]
Here's a running example: http://ideone.com/UGwFwq
If you would not like double reported when there are 4 (or more) equals in a row, a good way to prevent that from happening is simply keeping a temp variable on the previous "3 in a row" was found and check against that before you append to the dupes list.
Something like this:
var list = new[] { 80,81,90,90,90,90,90,90,100,85,86,86,79,95,95,95,95 };
var dupes = new List<int>();
int? prev = null;
for(var i = 2; i < list.Length; i++) {
if(list[i] == list[i - 1] && list[i] == list[i - 2]) {
if(!prev.HasValue || prev.Value != list[i]) {
dupes.Add(list[i]);
prev = list[i];
}
}
}
Showcase: http://ideone.com/jbokMQ
[Edit 2]
And if for some reason you need to run this in a LINQ-like manner (for instance if you have a HUGE dataset or a stream of data and you want to run this in a lazy manner), a solution to that can be found here: http://ideone.com/R1ZBVk