Link to home
Start Free TrialLog in
Avatar of pYrania
pYrania

asked on

Remove duplicates from Arraylist populated by Active Directory

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.

#####
contacts.Sort();
for (int i=1; i <= contacts.Count-1; i++)
{
      Console.WriteLine(contacts[i]);
      Console.WriteLine(contacts[i-1]);
      if(contacts[i] == contacts[i-1])
      {
            Console.WriteLine("Duplicate: "+contacts[i]);
      }
}
#####

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 = "(mail=frank.lattuca@saarland.ikk.de)";

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
ASKER CERTIFIED SOLUTION
Avatar of SRigney
SRigney
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pYrania
pYrania

ASKER

You are the man.

6 duplicates out of 998 contacts, not that bad. :)