473,327 Members | 2,081 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,327 software developers and data experts.

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 4647
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
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
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
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
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
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
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
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
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
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
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.