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.Prop erties["ma il"].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("Duplica te: "+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@saarl and.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.ArrayLi st
The following code should sort a list of email adresses, which I recieve from our AD (contacts.Add(contact.Prop
#####
contacts.Sort();
for (int i=1; i <= contacts.Count-1; i++)
{
Console.WriteLine(contacts
Console.WriteLine(contacts
if(contacts[i] == contacts[i-1])
{
Console.WriteLine("Duplica
}
}
#####
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@saarl
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.ArrayLi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
6 duplicates out of 998 contacts, not that bad. :)