best deal with value pairs that contain duplicates

R

rno

Hi,

I'm sorry if I'm asking for the obvious - my head is spinning a bit
trying to learn this c# stuff.

I have a list of paired values in the form of:

stringA, string1
stringB, string2
stringC, string1
stringC, string3
stringD, string2
etc..

I need to store these value pairs into some kind of collection. Since
I do not have unique 'keys', I cannot use a Dictionary or SortedList.
The combination of -say- stringA+string1 *will* be unique. (if
case-sensitive). That could serve as a key, but then I need to store 2
values.

My goal is to query the collection for stringA, and find all
associated strings 1, 2, etc.

My current idea is to create a simple 3-field table in a dataset.
Another way -since this is for a Form app- could be to use an
invisible ListView (not too keen on that). Either way, I have a
feeling I might be overly complicating things.

I'd appreciate some general advice on how to best deal with this.

tia
arno
 
A

Arne Vajhøj

Hi,

I'm sorry if I'm asking for the obvious - my head is spinning a bit
trying to learn this c# stuff.

I have a list of paired values in the form of:

stringA, string1
stringB, string2
stringC, string1
stringC, string3
stringD, string2
etc..

I need to store these value pairs into some kind of collection. Since
I do not have unique 'keys', I cannot use a Dictionary or SortedList.
The combination of -say- stringA+string1 *will* be unique. (if
case-sensitive). That could serve as a key, but then I need to store 2
values.

My goal is to query the collection for stringA, and find all
associated strings 1, 2, etc.

My current idea is to create a simple 3-field table in a dataset.
Another way -since this is for a Form app- could be to use an
invisible ListView (not too keen on that). Either way, I have a
feeling I might be overly complicating things.

I'd appreciate some general advice on how to best deal with this.

Based on how you intend to use it then a:

Dictionary<string,List<string>>

looks obvious to me.

Arne
 
R

rno

(e-mail address removed)>, (e-mail address removed)
says...>
Or hash table, which allows for collisions.

Tx guys. I also found the KeyValuePair struct, which might come in
handy.

arno
 
G

Göran Andersson

RayLopez99 said:
Or hash table, which allows for collisions.

A HashTable doesn't allow for collisions. The key has to be unique, the
hash code of the key is only used for performance, not instead of the key.
 
A

Arne Vajhøj

Or hash table, which allows for collisions.

Hashtable (or if .NET version >= 2.0 Dictionary<string,String>)
can not have multiple values for the same key.

Arne
 
R

RayLopez99

Tx guys. I also found the KeyValuePair struct, which might come in
handy.

You are welcome. I think KeyValuePair is simply a fancy name for
Dictionary, at least that's how I interpret it.

RL
 
J

Jeff Johnson

You are welcome. I think KeyValuePair is simply a fancy name for
Dictionary, at least that's how I interpret it.

Close. A KeyValuePair<K, V> is the generic version of what in pre-generic
..NET was called a DictionaryEntry. They aren't dictionaries themselves,
rather they're what dictionaries contain.
 

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