<newbie> Dictionay.ContainsValue problem

J

Jeff

..net 2.0

I have a Dictionay object Dictionay<int, string> in my app. This dictionary
holds values like these:
0, "NOOB"
0, "HELLO WORLD"
0, "TEST"
1, "BUG"
1, "CRASH"
1, "NOOB"

I want to perform a check against this dictionay object to determine if a
specific key & value already exists in the dictionay object.

the main goal with this code is that I have a foreach loop where I loop
through a result from a DataTable.Select query, and for each row in the
resultset I check if the value already exist in the dictionay. If it don't
exist in the dictionay object I then add it. Trying to implement a "select
distinct" feature

any suggestions?

Jeff
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Jeff said:
.net 2.0

I have a Dictionay object Dictionay<int, string> in my app. This dictionary
holds values like these:
0, "NOOB"
0, "HELLO WORLD"
0, "TEST"
1, "BUG"
1, "CRASH"
1, "NOOB"

Eh... No, it doesn't. You can't have several items with the same key.
I want to perform a check against this dictionay object to determine if a
specific key & value already exists in the dictionay object.

To use a dictionary efficiently, you should check against the key only.
If the unique value of the item consists of several properties, you
should construct a single value from those properties that you can use
as key.
the main goal with this code is that I have a foreach loop where I loop
through a result from a DataTable.Select query, and for each row in the
resultset I check if the value already exist in the dictionay. If it don't
exist in the dictionay object I then add it. Trying to implement a "select
distinct" feature

If you read the data from a database, it already has a distinct feature,
that is much faster.
 

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