weird hashtable behaviour ..is a bug ?

  • Thread starter Thread starter Pankaj
  • Start date Start date
P

Pankaj

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
 
Pankaj said:
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.

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.
 
Back
Top