Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How do you check to see if a key exists in a Dictionary?
Posted

You can tell if a dictionary has a key in it because it won't close properly, unless it's a really small key.

Honestly, you spent more time typing that message than it would have taken to just look yourself. Documentation[^] It's not just there for fun.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-Aug-11 23:03pm    
Exactly. Also, it could be hard to tell if the dictionary is really big. My 5.
--SA
Just use ContainsKey Method[^] to check a key existence in the dictionary.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-Aug-11 23:08pm    
Sure, a 5. I credited your answer in mine -- another way is TryGetValue, please see my answer.
--SA
Wonde Tadesse 6-Dec-11 11:18am    
Thanks
In addition to what Wonde advised: you can also use System.Collections.Generic.Dictionary.TryGetValue, see http://msdn.microsoft.com/en-us/library/bb347013.aspx[^].

To confirm what SK Genius say, you would spent more time typing that message than it would have taken to just look yourself.

—SA
 
Share this answer
 
Comments
Wonde Tadesse 17-Aug-11 23:08pm    
5+. Another possible solution.
Sergey Alexandrovich Kryukov 17-Aug-11 23:09pm    
Thank you, Wonde. How could you be so fast?
--SA
Wonde Tadesse 17-Aug-11 23:23pm    
No wonder.I'm fast like lightning.:) Just kidding.As usual I was browsing the Q/A sections and suddenly my reputation points up lifted drastically.Finally I just checked my answers what I replied ... I am here look what I got.
Sergey Alexandrovich Kryukov 17-Aug-11 23:27pm    
We're more overwhelmed by tons of bad questions these days, have less time to review each others solutions...
--SA
Wonde Tadesse 17-Aug-11 23:35pm    
Very True. These days I am quite busy in office. I am less active than before. But still I am checking some members solution.
Have you searched in google[^]?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900