VERY Simple example:
public class ClientState : IComparable<ClientState>
{
public int ID { get; set; }
public string State { get; set; }
public override string ToString()
{
return String.Format("ID: {0}, State: {1}", ID, State);
}
#region IComparable<ClientState> Members
public int CompareTo(ClientState other)
{
return other.State.CompareTo(State);
}
#endregion
}
static void Main(string[] args)
{
List<ClientState> clientStates = new List<ClientState>
{
new ClientState() {ID = 1, State = "state 1"},
new ClientState() {ID = 2, State = "state 1"},
new ClientState() {ID = 4, State = "state 3"},
new ClientState() {ID = 11, State = "state 2"},
new ClientState() {ID = 14, State = "state 1"},
new ClientState() {ID = 15, State = "state 2"},
new ClientState() {ID = 21, State = "state 1"},
new ClientState() {ID = 20, State = "state 2"},
new ClientState() {ID = 51, State = "state 1"}
};
removeDuplicates(clientStates);
Console.ReadLine();
}
private static void removeDuplicates(IList<ClientState> clientStatesWithPossibleDuplicates)
{
for (int i = 0; i < clientStatesWithPossibleDuplicates.Count; ++i)
{
for (int j = 0; j < clientStatesWithPossibleDuplicates.Count; ++j)
{
if (i != j)
{
if (clientStatesWithPossibleDuplicates[i].CompareTo(clientStatesWithPossibleDuplicates[j]) == 0)
{
clientStatesWithPossibleDuplicates.RemoveAt(i);
i = 0;
}
}
}
}
}
Output:
ID: 4, State: state 3
ID: 20, State: state 2
ID: 51, State: state 1