Accessing Hashtable of Arrays

G

George W.

In perl I'm used to using hashtables of arrays and accessing a
particular element like this:
$HoA{flintstones}[0]

Simple as that. How do I access and update values of arrays stored in
my hashtable within C#? I've looked all over the place and I don't see
any provision for doing this. I'd rather not have to write a bunch of
code to do something that is trivial in other languages.
 
H

Huibert-Jan Nieuwkamer

In perl I'm used to using hashtables of arrays and accessing a
particular element like this:
$HoA{flintstones}[0]

Simple as that. How do I access and update values of arrays stored in
my hashtable within C#? I've looked all over the place and I don't see
any provision for doing this. I'd rather not have to write a bunch of
code to do something that is trivial in other languages.


myHT[key]

If you want to access by index as well use System.Collections.SortedList
http://msdn.microsoft.com/library/d...us/cpref/html/frlrfSystemStringClassTopic.asp
 
A

Angelos Karantzalis

It just a matter of a cast:

((string[])HoA[key])[index] ... just substitute string[] with your array
type, and of course key & index with the appropriate values.
 
G

George W.

Perfect. See, this needs to be in a book somewhere, because I checked
every book I could think of for this. Although, I didn't check the
O'Reilly books, so maybe it was in there :/

Thanks for the help, though.

Angelos said:
It just a matter of a cast:

((string[])HoA[key])[index] ... just substitute string[] with your array
type, and of course key & index with the appropriate values.

In perl I'm used to using hashtables of arrays and accessing a
particular element like this:
$HoA{flintstones}[0]

Simple as that. How do I access and update values of arrays stored in
my hashtable within C#? I've looked all over the place and I don't see
any provision for doing this. I'd rather not have to write a bunch of
code to do something that is trivial in other languages.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top