473,395 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Hashtables: readding a removed object

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

Nov 22 '05 #1
1 1283
<mi**********@gmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Cengiz Dincoglu | last post by:
When I insert a long value as key and the object to a hashtable. it fails at about 600,000 data points. ht.add(long, long) We are developing a real time application that is required to keep...
1
by: midnightswan | last post by:
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...
6
by: Michael Schollmeyer | last post by:
Hello, The following code writes the text string: Uri uri1 = new Uri("http://www.here.net/aplace?param=one"); Uri uri2 = new Uri("http://www.here.net/aplace?param=two"); int h1 =...
4
by: Michael Maercker | last post by:
hi! i'm wondering what the differences are between hashtables und dictionarybases; can both of them store several different types of objects, each accessible by a string key? currently i'm using a...
4
by: Anders Borum | last post by:
Hello! I'm am currently working on making a central cache component threadsafe, and was looking at the synchronized implementation of the Hashtable. I was wondering why you'd really want to...
1
by: Curtis | last post by:
Does anyone know the proper method to save information to embedded hashtables. I am trying to save parent/child information to hashtables but I am not getting the correct results I have made a...
6
by: Erick | last post by:
I've created a class called Procs and a collection class called Processes which uses a hastable object to store the Procs. Now i want to enumerate with the "For each" to extract all the Procs in...
2
by: PAzevedo | last post by:
I have this Hashtable of Hashtables, and I'm accessing this object from multiple threads, now the Hashtable object is thread safe for reading, but not for writing, so I lock the object every time I...
0
by: John Smith | last post by:
Hello people, I have a performance query regarding LINQ that I would like some opinions. Currently we have a business logic framework that is used in n-tier applications. We read data from a...
0
by: Jake McCool | last post by:
Hello people, I have a performance query regarding LINQ that I would like some opinions. Currently we have a business logic framework that is used in n-tier applications. We read data from a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.