Solved

Remove duplicates from Arraylist populated by Active Directory

Posted on 2004-08-05
2
4,791 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now