473,662 Members | 2,390 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("Sco re", 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.ToS tring() + " / " + fields[o].ToString());
}
Nov 16 '05 #1
2 4695
choyk1 <an*******@disc ussions.microso ft.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
choyk1 <an*******@disc ussions.microso ft.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.co m>
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
1755
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 a foreach(type var in hashTable) the items are DictionaryEntries. I was expecting these to be the values. So, do I do foreach(type var in hashTable.Values) instead?
3
5092
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 orders quarterly, and at the same time how many different item numbers used in each quarter.
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 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. ...
13
1373
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 TRACKMOUSEEVENTs. This happens if I disable/enable a menuitem, add a new menuitem programatically or click on an entry in the mdiList menu. I am disposing the main menu in the child form as well as in the main mdi form, so that's not the issue. I have seen...
4
25909
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 that as the items are inserted, they are not arranged in the hash at the order they were inserted by. Is there a way to control that with a hashtable ? I can't even sort it... Thanks
8
2040
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 products whatsoever. Now click or page up/down away from this new record. You just created a new order without a single item having been ordered. Not something a user should be able to do.
5
1966
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 moment I have approx 10 objects with ids that are spread out, e.g 1, 12, 24, 56, 200,320....
5
11269
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, right? How do I loop through a Hashtable to selectively remove items?
4
4820
by: Adam Right | last post by:
How can i add a collection to another collection ? For example : --------------------------------------------- StringCollection strColl= new StringCollection(); //string series Hashtable hshCol= new Hashtable(); // main collection for string series strColl.Add("white"); //first series starting strColl.Add("hot"); strColl.Add("little");
0
1037
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 what I would have expected is that the actual hashtable be removed. I cannot see an other reason that the items would be removed, other than by the Cache itself.
0
8432
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8343
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8856
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8762
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8545
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6185
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.