List<double> DeDuplList(List<double> _List)
{
if (_List.Count < 1)
return new List<double>();
for (int i = 0 ; i < _List.Count -1 ; i++)
{
double st1 = _List[i+1];
double nd2 = _List[i];
if (st1 == nd2)
{
_List.Remove(st1);
}
}
return _List;
}​
Tested ok:
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
List<double> duplList = new List<double> {1.1, 2.2, 2.2, 3.3, 4.4, 5.5, 5.5, 6.6, 7.7};
Console.WriteLine(" ");
for (int i = 0; i < duplList.Count; i++)
{
Console.WriteLine("DuplList List Items indices: " + i + " DuplList List Items: " + duplList[i]);
}
List<double> DeDuplList(List<double> _List)
{
if (_List.Count < 1)
return new List<double>();
for (int i = 0 ; i < _List.Count -1 ; i++)
{
double st1 = _List[i+1];
double nd2 = _List[i];
if (st1 == nd2)
{
_List.Remove(st1);
}
}
return _List;
}
duplList = DeDuplList(duplList);
Console.WriteLine(" ");
for (int i = 0; i < duplList.Count; i++)
{
Console.WriteLine("DeDuplList List Items indices: " + i + " DeDuplList List Items: " + duplList[i]);
}
}
}​
Output:
DuplList List Items indices: 0 DuplList List Items: 1.1
DuplList List Items indices: 1 DuplList List Items: 2.2
DuplList List Items indices: 2 DuplList List Items: 2.2
DuplList List Items indices: 3 DuplList List Items: 3.3
DuplList List Items indices: 4 DuplList List Items: 4.4
DuplList List Items indices: 5 DuplList List Items: 5.5
DuplList List Items indices: 6 DuplList List Items: 5.5
DuplList List Items indices: 7 DuplList List Items: 6.6
DuplList List Items indices: 8 DuplList List Items: 7.7
DeDuplList List Items indices: 0 DeDuplList List Items: 1.1
DeDuplList List Items indices: 1 DeDuplList List Items: 2.2
DeDuplList List Items indices: 2 DeDuplList List Items: 3.3
DeDuplList List Items indices: 3 DeDuplList List Items: 4.4
DeDuplList List Items indices: 4 DeDuplList List Items: 5.5
DeDuplList List Items indices: 5 DeDuplList List Items: 6.6
DeDuplList List Items indices: 6 DeDuplList List Items: 7.7
Return empty list

Comment