Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

<newbie> Dictionay.ContainsValue problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff - 23 Jul 2007 09:39 GMT
.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
Göran Andersson - 23 Jul 2007 10:01 GMT
> .net 2.0
>
[quoted text clipped - 6 lines]
> 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.

Signature

Göran Andersson
_____
http://www.guffa.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.