Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

algorithm to find all unique email id strings in an array

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sfdev2000@yahoo.com - 22 Feb 2008 15:40 GMT
I'm wrestling with the best way to create some C# code to find all of
the unique email id strings I receive within an array.  Basically I
want to efficiently eliminate all of the duplicates.  Typically there
will be between 1 and a few hundred unique email ids, and worse case
it might be 20,000 to 50,000 unique email ids.

My first pass was to use a C# hashtable.  I use the hashtable to tell
me whether or not I've already seen the  email id string in the
array.  I don't care about the ordering of the email ids, all I care
about is finding all of the unique email ids.

Does anyone have any suggestion for a better solution?

Are there are gotchas for using a C# hashtable for this solution?
Jon Skeet [C# MVP] - 22 Feb 2008 15:47 GMT
> I'm wrestling with the best way to create some C# code to find all of
> the unique email id strings I receive within an array.  Basically I
[quoted text clipped - 10 lines]
>
> Are there are gotchas for using a C# hashtable for this solution?

It would help if you'd say which version of .NET you're using.

In .NET 3.5 I'd just call Distinct() on the array.
In .NET 2.0 I'd use a Dictionary<string,string> using the same value as
the key.
In .NET 1.1 I'd use Hashtable.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Arne Vajhøj - 22 Feb 2008 22:07 GMT
> I'm wrestling with the best way to create some C# code to find all of
> the unique email id strings I receive within an array.  Basically I
[quoted text clipped - 8 lines]
>
> Does anyone have any suggestion for a better solution?

If on 3.5 then HashSet was a possibility.

Arne
Jon Skeet [C# MVP] - 22 Feb 2008 22:17 GMT
> > I'm wrestling with the best way to create some C# code to find all of
> > the unique email id strings I receive within an array.  Basically I
[quoted text clipped - 10 lines]
>
> If on 3.5 then HashSet was a possibility.

You *could* explicitly use a HashSet - but why go to the work of doing
it yourself when Enumerable.Distinct() does it all for you? :)

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Arne Vajhøj - 23 Feb 2008 03:35 GMT
>>> I'm wrestling with the best way to create some C# code to find all of
>>> the unique email id strings I receive within an array.  Basically I
[quoted text clipped - 12 lines]
> You *could* explicitly use a HashSet - but why go to the work of doing
> it yourself when Enumerable.Distinct() does it all for you? :)

When you have a hammer problems tend to look like nails.

:-)

Is .Discrete using a HashSet internally ?

Arne

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.