Hashtables: readding a removed object

M

midnightswan

Hi,

I've got a hashtable that contains of list of remote network Player
objects. The unique key used is the Player's IP address as a string.

The problem I'm getting is when a Player disconnects I do a

_RemotePlayer.remove[ipKey];

However, if the Player joins the game again and I add a new Player
object with the same IP address being the key to the hashtable I get an
ArguementException.

It seems to me that when I remove the Player from the hashtable the key
is not removed as well. How do I remove the key from the table? Am I
able to do that? or do hashtables always keep a used key and I have to
do a .ContainsKey check on it before adding players to the table?


Thanks in Advance,
MS
 
J

Jon Skeet [C# MVP]

I've got a hashtable that contains of list of remote network Player
objects. The unique key used is the Player's IP address as a string.

The problem I'm getting is when a Player disconnects I do a

_RemotePlayer.remove[ipKey];

I suspect that's not what you actually do, as that won't compile.
However, if the Player joins the game again and I add a new Player
object with the same IP address being the key to the hashtable I get an
ArguementException.

It seems to me that when I remove the Player from the hashtable the key
is not removed as well. How do I remove the key from the table? Am I
able to do that? or do hashtables always keep a used key and I have to
do a .ContainsKey check on it before adding players to the table?

If you were actaully managing to remove the player from the hashtable,
you wouldn't have a problem. I suspect it's the removal side of things
which is the problem.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top