Solved

Remove duplicates from Arraylist populated by Active Directory

Posted on 2004-08-05
2
4,800 Views
Last Modified: 2011-10-03
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
0
Comment
Question by:pYrania
2 Comments
 
LVL 15

Accepted Solution

by:
SRigney earned 500 total points
ID: 11725461
I believe the problem is because you are comparing the objects, not the values of the string.

Try this.

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

Author Comment

by:pYrania
ID: 11725532
You are the man.

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

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question