From: rno on
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

From: Arne Vajhøj on
On 15-02-2010 18:48, rno wrote:
> 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
From: RayLopez99 on
On Feb 16, 2:47 am, Arne Vajhøj <a...(a)vajhoej.dk> wrote:

> Based on how you intend to use it then a:
>
> Dictionary<string,List<string>>
>
> looks obvious to me.
>
> Arne

Or hash table, which allows for collisions.
From: rno on
In article <5367ba9c-681d-4c74-b2ae-
da312128d0bd(a)x22g2000yqx.googlegroups.com>, raylopez88(a)gmail.com
says...>
> On Feb 16, 2:47 am, Arne Vajhøj <a...(a)vajhoej.dk> wrote:
>
> > Based on how you intend to use it then a:
> >
> > Dictionary<string,List<string>>
> >
> > looks obvious to me.
> >
> > Arne
>
> Or hash table, which allows for collisions.

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

arno
From: Göran Andersson on
RayLopez99 wrote:
> On Feb 16, 2:47 am, Arne Vajh�j <a...(a)vajhoej.dk> wrote:
>
>> Based on how you intend to use it then a:
>>
>> Dictionary<string,List<string>>
>>
>> looks obvious to me.
>>
>> Arne
>
> 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.

--
G�ran Andersson
_____
http://www.guffa.com