473,387 Members | 1,535 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,387 software developers and data experts.

VB.net For Each through Hashtable?

Hi,

I would like to go through a hashtable and take the next value

to save it into an ArrayList.

How to do that in the most easiest way???

I am looking for something like:

For Each Object value In clientsHashTable

dropDownList.Add(value)

End for | NEXT value

Return dropDownList.ToArray

Thx,

Stefan
Jul 21 '05 #1
3 23658
Stefan Richter <sp**@spammenot.com> wrote:
I would like to go through a hashtable and take the next value

to save it into an ArrayList.

How to do that in the most easiest way???

I am looking for something like:

For Each Object value In clientsHashTable

dropDownList.Add(value)

End for | NEXT value

Return dropDownList.ToArray


Using For Each with a Hashtable gives you DictionaryEntry references -
you can then look at the Key and Value properties. Here's a sample:

Option Strict On

Imports System
Imports System.Collections

Public Class Test

Public Shared Sub Main()
Dim table As New Hashtable()

table.Add ("Key1", "Value1")
table.Add ("Key2", "Value2")

Dim entry As DictionaryEntry
For Each entry in table
Console.WriteLine ("{0}={1}", entry.Key, entry.Value)
Next
End Sub
End Class

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Okay, that worked fine.
But how can I access a single entry,

like I want to get the key for a certain value or the value for a certain
key???

Stefan
Jul 21 '05 #3
Stefan Richter <sp**@spammenot.com> wrote:
Okay, that worked fine.
But how can I access a single entry,

like I want to get the key for a certain value or the value for a certain
key???


If you want the key for a certain value, that suggests you've got your
hashtable the wrong way round - I suggest you keep two hashtables, one
for key -> value, and one for value -> key.

For key -> value, use the indexer:

value = hashtable(key)

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

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

Similar topics

18
by: JezB | last post by:
How can I loop thru a hashtable changing the Value of each entry ? Whatever I try I always seem to get the error about modifying the collection within the loop.
3
by: Kakaiya | last post by:
Error message: An unhandled exception of type 'System.InvalidCastException' occurred in test.dll Additional information: Specified cast is not valid. Public Class Form1 Inherits...
2
by: Tony | last post by:
I have this problem - I have a hashtable, containing a list of filenames. Every 60 seconds, I have a thread that enumerates thru this hashtable, and based on some simple logic, some of the items...
8
by: Robin Tucker | last post by:
When I create a hashtable hashing on Object-->Item, can I mix "string" and "integer" as the key types? I have a single thumbnail cache for a database with (hashed on key) and a file view (hashed...
10
by: Ken Foster | last post by:
I have a hashtable keyed by some name, holding an instance of an object. Most of the time I use the hashtable in the traditional sense, given a name, I lookup the object, then I run a method on...
7
by: J L | last post by:
I have defined a structure private structure FieldInfo dim FieldName as string dim OrdinalPostioin as Integer dim DataType as Type dim Size as Integer end structure I read this information...
10
by: Q | last post by:
Hi, I'm using a hashtable to store away a bunch of numbers from my array: The Hashtable should look like: Key Value 1 01234 2 01235
2
by: Scott M. Lyon | last post by:
I'm working on using the COM Interop wrapper on an existing .NET library, to allow existing VB6 applications to call the .NET code. And I've been able to get it working in a basic sense (I can...
17
by: John A Grandy | last post by:
For a Hashtable that is expected to contain no more than 100 DictionaryEntry elements , what is the best load factor ? ( This Hashtable is a encapsulted in a class , an instance of which is...
10
by: chrisben | last post by:
Hi, Here is the scenario. I have a list of IDs and there are multiple threads trying to add/remove/read from this list. I can do in C# 1. create Hashtable hList = Hashtable.Synchronized(new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.