Best Collection?

C

C# Learner

What's the best collection for the following scenario:

key value
--- -----

"Languages" -> "C#"
-> "Delphi"
-> "C++"

"IDEs" -> "VS.NET"
-> "BDS"
-> "KDevelop"

Basically we have a string /key/ with one of more string /values/.

I'd guess that 'NameValueCollection' would be usable here but is it the
best class for this?
 
J

Jon Skeet [C# MVP]

C# Learner said:
What's the best collection for the following scenario:

key value
--- -----

"Languages" -> "C#"
-> "Delphi"
-> "C++"

"IDEs" -> "VS.NET"
-> "BDS"
-> "KDevelop"

Basically we have a string /key/ with one of more string /values/.

I'd guess that 'NameValueCollection' would be usable here but is it the
best class for this?

It's certainly an easy class to use, so long as you make sure you use
Add and GetValues rather than just the indexer.

Another alternative would be to use a Hashtable where the value was an
ArrayList of strings.
 
C

C# Learner

Jon Skeet [C# MVP] wrote:

[...]
It's certainly an easy class to use, so long as you make sure you use
Add and GetValues rather than just the indexer.

Another alternative would be to use a Hashtable where the value was an
ArrayList of strings.

Thanks Jon. The latter sounds like a good idea but I think I'll go with
the former in this instance.

Bye.
 

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