Remove duplicates from Arraylist populated by Active Directory
Posted on 2004-08-05
Over here, I've got a problem with out Exchange 2003 Server, probably during migration from 5.5 -> 2003 some mail addresses were duplicated with different CNs.
The following code should sort a list of email adresses, which I recieve from our AD (contacts.Add(contact.Properties["mail"].Value.ToString());) and print out duplicated ones.
for (int i=1; i <= contacts.Count-1; i++)
if(contacts[i] == contacts[i-1])
As you can see, I'm outputting the email addresses it's going to check, and yes, they are the same - of course. I'm searching for the exact email adresse with objSearcher.Filter = "(email@example.com)";
However the if condition returns false.
Now, if I'd check if the .GetHashCode() of contacts[x] are the same, it returns true.
Am I save to use the hash for comparing?
Why aren't the equal strings equal?
FYI: contacts is a System.Collections.ArrayList