The problem is that you're decrementing l
with each iteration inner-most for
-loop. Try rewriting it like this:
for (int i = 0; i < l; i++)
{
for (int j = i + 1; j < l;)
{
if(count_list[j] == count_list[i]){
l--;
for (int k = j; k < l; k++)
{
count_list[k] = count_list[k + 1] ;
}
break;
}
else{
j++;
}
}
}
And remember to call Resize
if you want to shrink the array back down at the end:
Array.Resize(ref count_list, l);
However, this is a lot of unnecessary work. I'd strongly suggest using a HashSet<T>
or Linq's Distinct
extension method:
count_list = count_list.Distinct().ToArray();