name value pair

  • Thread starter Andy Sutorius via DotNetMonster.com
  • Start date
A

Andy Sutorius via DotNetMonster.com

Hi,

What collection can I use to store name value pairs that contain duplicates
in both columns?

Thanks,

Andy
 
Y

Yunus Emre ALPÖZEN [MCSD.NET]

You can use a datatable which is to generic...

But if both column's composition is unique, u can use hash table for fast
access. For instance,

Sample Data:
A 1
B 1
C 2
A 2
B 3

If u have data like this,

u can use hash table
either
concatenating key value pairs with a special separator such as "$_$".
and use this string as hash value
or
just use keys as keys and use an arraylist for the changing values
A shows an arraylist containing 1,2
B shows an arraylist containing 1, 3
C should show aan arraylist containing 2

Hope this helps,
 
G

Guest

I don't thinks you can add
A 1
B 1
C 2
A 2
B 3

to a Hashtable. Using Hashtable, key must be unique. In above data, it will
throw ArgumentException: Item has already been used...

Elton Wang

Yunus Emre ALPÖZEN said:
You can use a datatable which is to generic...

But if both column's composition is unique, u can use hash table for fast
access. For instance,

Sample Data:
A 1
B 1
C 2
A 2
B 3

If u have data like this,

u can use hash table
either
concatenating key value pairs with a special separator such as "$_$".
and use this string as hash value
or
just use keys as keys and use an arraylist for the changing values
A shows an arraylist containing 1,2
B shows an arraylist containing 1, 3
C should show aan arraylist containing 2

Hope this helps,
 
Y

Yunus Emre ALPÖZEN [MCSD.NET]

Just read my post again. I advised two solution two overcome this issue....

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCSD.NET

Elton W said:
I don't thinks you can add
A 1
B 1
C 2
A 2
B 3

to a Hashtable. Using Hashtable, key must be unique. In above data, it
will
throw ArgumentException: Item has already been used...

Elton Wang
 
G

Guest

So I only think the second is wrong.

Yunus Emre ALPÖZEN said:
Just read my post again. I advised two solution two overcome this issue....

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCSD.NET
 
G

Guest

Hi Joseph,

It's quite interesting. NameValueCollection also stores key/value pairs by
unique keys. However, different from HashTable, it can 'Add' multi-values to
one key, e.g.
NvCollection.Add("A","1");
NvCollection.Add("A","2");
The result is that it concatenates values separated by comma, e.g.
NvCollection(“Aâ€) = “1,2â€. It seems you can use
string.split(",".ToCharArray()) to get an value array. But suppose there is
one value with comma, e.g. "1,000", how do you deal with it?

Elton Wang
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top