473,508 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Orders adding items to Hashtable.

I intended to save properties of an object to a Hashtable. In this case, keys and values are not fixed types and I cannot use SortedList.

I have no idea what order the .NET framework add items to Hashtable when Add(key, value) method is applied. Monitoring the position items are added, I cannot find if key is the standard or value.

I thought basically Hashtable function acts randomly, therefore the order will be changed unexpectedly.

However :

foreach (object o in objs)
{
CheckSomething(o, ref e81_o, ref l83_hn, ref l83_o, ref score);
Hashtable fields = o.Fields;
fields.Add("E81_O", e81_o);
fields.Add("L83_HN", l83_hn);
fields.Add("L83_O", l83_o);
fields.Add("Score", score);
}

In the case above, iteratively fields in all objs have the same order! For example, o.Fields has items originally in the order like,

H
V
S
E

and all objs have fields in the same order like below,

Score
L83_O
H
L83_HN
V
E81_O
S
E

But, extracting items in the reverse order like Stack.

Hashtable fields = new Hashtable();
foreach (object o in fields.Keys)
{
sb.Append(o.ToString() + " / " + fields[o].ToString());
}
Nov 16 '05 #1
2 4670
choyk1 <an*******@discussions.microsoft.com> wrote:
I intended to save properties of an object to a Hashtable. In this
case, keys and values are not fixed types and I cannot use
SortedList.

I have no idea what order the .NET framework add items to Hashtable
when Add(key, value) method is applied. Monitoring the position items
are added, I cannot find if key is the standard or value.


I'm not really sure of what your question is, but you shouldn't rely on
the order in which things come out of a hashtable. In some situations
it may *look* like it's ordered in a particular way, but that's likely
to be coincidence rather than anything else.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
choyk1 <an*******@discussions.microsoft.com> wrote:
I intended to save properties of an object to a Hashtable. In this
case, keys and values are not fixed types and I cannot use
SortedList.

I have no idea what order the .NET framework add items to Hashtable
when Add(key, value) method is applied. Monitoring the position items
are added, I cannot find if key is the standard or value.


I'm not really sure of what your question is, but you shouldn't rely on
the order in which things come out of a hashtable. In some situations
it may *look* like it's ordered in a particular way, but that's likely
to be coincidence rather than anything else.

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

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

Similar topics

1
1746
by: Lee | last post by:
I am new to the C# language and I am trying to figure out a couple of things. 1) How do I get the first item from a Hashtable? For example: in VB6 this would be hashTable.item(1) 2) When I do...
3
5088
by: Anne | last post by:
Hi I have got a table with some sales transactions. It has got 3 fields 1) Ordernumber 2) Item number 3) Shippingdate Now I want to make ONE (not two) query that shows how many different...
0
341
by: choyk1 | last post by:
I intended to save properties of an object to a Hashtable. In this case, keys and values are not fixed types and I cannot use SortedList. I have no idea what order the .NET framework add items to...
13
1355
by: Rich B. | last post by:
I have an MDI form with a single child form. I have found a couple of circumstances that appear to cause the framework to leak Int32s, MenuItems, MenuItemCollections and sometimes...
4
25851
by: Nadav | last post by:
Hello. I have a Hashtable, to which I insert key and values. When I go over the hashtable with "foreach" later on, the items are not coming out at the order I inserted them. A quickwatch showed...
8
2032
by: Martin | last post by:
I hope not, but, I think the answer to this question is "it can't be done". Northwind sample database. Orders form. Go to a new record. Select a customer in "Bill To:" Don't enter any...
5
1959
by: Macca | last post by:
Hi, I have a number of objects i would like to store in a list like struture. They already have ID's associated with them so i would like to utilise these ids as accessors the list.. At the...
5
11248
by: Jen | last post by:
The usual trick to get around the "collection was modified" problem by looping through the collection backwards by index won't work with a Hashtable because there is no way to access by index,...
4
4788
by: Adam Right | last post by:
How can i add a collection to another collection ? For example : --------------------------------------------- StringCollection strColl= new StringCollection(); //string series Hashtable...
0
1029
by: bloodsugarsuckerfish | last post by:
Hi all, I have in the ASP.NET cache a Hashtable of items. What seems to be happening,is that some of the actual entries in the hashtable are being removed, perhaps under memory pressure, when...
0
7225
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
7123
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
7383
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...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.