473,387 Members | 1,516 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,387 software developers and data experts.

Value types in a hashtable

Udi
Hi,
I need to store an int in a hashtable and still be able to work on it
outside the hash.
I mean I'd like to store in the hash the int's pointer and not the int
itself to overcome the boxing procedure.
Can it be done?
Do you have other ideas?
Thanks.

Apr 25 '06 #1
3 2042
Well, not if you want to work with it both inside and outside... plus you
are likely to trash the hash-tables integrity if the integer (and thus it's
hash) changes while it is in the table; it will appear in the wrong
bucket...

An implementation strategy might be to place the integer as a field/property
on a custom class, and access it (in both cases) via the class; kinda like
providing your own boxing via provision of a shared object that all callers
can use. But: you still (IIRC) can't really change the hash value of
something that is already inside a hash table...

Marc
Apr 25 '06 #2
Note also that in 2.0 you could use Dictionary<TKey, TValue>, which (I
believe) avoids the box.

Marc
Apr 25 '06 #3
You could wrap the int in a class and put the class in the Hashtable.

Udi wrote:
Hi,
I need to store an int in a hashtable and still be able to work on it
outside the hash.
I mean I'd like to store in the hash the int's pointer and not the int
itself to overcome the boxing procedure.
Can it be done?
Do you have other ideas?
Thanks.


Apr 25 '06 #4

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

Similar topics

3
by: suresh | last post by:
Hi all, I have a hash table and I want to modify the value of a key. Please let me know how can that be acheived. Thanks Suresh
4
by: Vladimir C. | last post by:
Hashtable map = new Hashtable(); map = 10; map = 20; foreach(DictionaryEntry e in map) { e.Value = 100; Console.WriteLine("{0}: {1}", key, map); }
1
by: Pavils Jurjans | last post by:
Hello, I am building custom hashtable class, and thinking about value retrieval issues. The thing is, that sometimes the hashtable value may contain value null. If someone is reading this value...
8
by: xmail123 | last post by:
Hi, As was pointed out whatever you return from a WebMethod needs to be serializable to SOAP. An ArrayList is not serializable. I will be needing to return other data types from web methods. ...
24
by: ALI-R | last post by:
Hi All, First of all I think this is gonna be one of those threads :-) since I have bunch of questions which make this very controversial:-0) Ok,Let's see: I was reading an article that When...
7
by: Dan | last post by:
I have the need to translate values back and forth. I have created a Hashtable to do this because I don't care about intrinsic order and I want it to be a fast as possible. My only concern is...
7
by: ad | last post by:
I have a hash table like: Hashtable myHT = new Hashtable(); myHT.Add("First", "Hello"); myHT.Add("Second", "World"); myHT.Add("Third", "!"); We can use key to find value like: myHT -> "Hello"...
5
by: Belee | last post by:
I have created a static class which contains properties. I can assign values to them when the software is running. How can I create default values for these properties when I am coding them, so...
2
by: bs | last post by:
I have a hashtable that contains structures. Is it possible to modify a value of one of these structures. It only seems to work if the hash contains class objects, not structures?
3
by: Rich | last post by:
Hello, I populate a hashtable with recordID's in a "For i=0 to n" loop. Some recordID's are duplicate but for different rows (recordID is not a key field in this scenario). I use the value of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.