473,405 Members | 2,421 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,405 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 4659
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
0
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...

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.