473,473 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Which is the right Collection for me?

Hi guys, I've trying to find a collection for a very common task without any luck.

I only need a collection of Key/Value objects, cause I need to check whether a key as been added and if not, get it in.
I thought a HashTable would be enough. The problem with HashTable and with SortedList is that they really "re-sort" the elements when a new element gets into the collection. So, when I loop throught the collection using a foreach or a GetEnumerator, the elements appear in a different order. I Don't want this to happen. I want to read the elements in the same order I created them. But I still need the "key search" functionally. I don't want to create a special class for this, I'm sure this is a quite simple task.

Thanks in advance.
Nov 16 '05 #1
2 1427
Add the objects to two collections. One hashtable and one array list. The hashtable will give you objects for keys and the array list will store them in the order you chose.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Tiësto" <a@a.com> wrote in message news:uj**************@TK2MSFTNGP11.phx.gbl...
Hi guys, I've trying to find a collection for a very common task without any luck.

I only need a collection of Key/Value objects, cause I need to check whether a key as been added and if not, get it in.
I thought a HashTable would be enough. The problem with HashTable and with SortedList is that they really "re-sort" the elements when a new element gets into the collection. So, when I loop throught the collection using a foreach or a GetEnumerator, the elements appear in a different order. I Don't want this to happen. I want to read the elements in the same order I created them. But I still need the "key search" functionally. I don't want to create a special class for this, I'm sure this is a quite simple task.

Thanks in advance.
Nov 16 '05 #2
So, none of the many collections can achieve this? Sounds strange... anyhow, I will to take the aproach you suggest, Thank you!
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message news:ua**************@TK2MSFTNGP10.phx.gbl...
Add the objects to two collections. One hashtable and one array list. The hashtable will give you objects for keys and the array list will store them in the order you chose.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



"Tiësto" <a@a.com> wrote in message news:uj**************@TK2MSFTNGP11.phx.gbl...
Hi guys, I've trying to find a collection for a very common task without any luck.

I only need a collection of Key/Value objects, cause I need to check whether a key as been added and if not, get it in.
I thought a HashTable would be enough. The problem with HashTable and with SortedList is that they really "re-sort" the elements when a new element gets into the collection. So, when I loop throught the collection using a foreach or a GetEnumerator, the elements appear in a different order. I Don't want this to happen. I want to read the elements in the same order I created them. But I still need the "key search" functionally. I don't want to create a special class for this, I'm sure this is a quite simple task.

Thanks in advance.
Nov 16 '05 #3

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

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
19
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
9
by: Anthony Bouch | last post by:
Everything I know about looping structures says to be careful about expressions that need to be evaluated again and again for each test/increment of a loop. I came across this piece of code the...
13
by: Dog Ears | last post by:
I've got a windows form that monitors the status of employees it polls a database every 2 seconds to fetch updates then update a underlying dataset bound to a grid using Invoke to marshal to the...
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
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
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
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...
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.