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 / .NET Framework / New Users / May 2004

Tip: Looking for answers? Try searching our database.

weird hashtable behaviour ..is a bug ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pankaj - 13 May 2004 20:44 GMT
Hi All,

I use a Hashtable in my program to keep unique items...at one instance I
need to repopulate this hashtable through a loop.
when starting repopulation  hashtable.count() returns ZERO hence first item
gets added successfully but as soon as the control reaches top of foreach
loop
somehow a second item which indeed existed before repoulation started
appears in hashtable and count returns two hence this second item can not
add itself because of duplicate key.

I tried allocating a new object to hashtable as well as clear() before
repopulating but same weird behaviour.

At the end I have to check in repopulation code that if key existed then
dont add it ...my code worked for time
but just wondering....why why why?

Any thoughts ?

-TIA
Pankaj
Jon Skeet [C# MVP] - 13 May 2004 21:00 GMT
> I use a Hashtable in my program to keep unique items...at one instance I
> need to repopulate this hashtable through a loop.
[quoted text clipped - 3 lines]
> appears in hashtable and count returns two hence this second item can not
> add itself because of duplicate key.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


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.