Solved

Getting a key for the value, form a Hashtable

Posted on 2006-10-24
4
223 Views
Last Modified: 2010-04-16
Hi,

can someone provide me the syntax below where I am trying to access the value that corresponds witha given Key?

Thanks,
Bob

            public string GetValueDescriptor( string keyDescriptor )
            {
                  if ( this.ContainsKey( keyDescriptor ) )
                  {
                        return (string)this[keyDescriptor];
                  }
                  return null;
            }

            public string GetStreetDescriptor( string valueDescriptor )
            {
                  if ( ContainsValue( valueDescriptor ) )                  
                  {
                        return (string)this.????????
                  }
                  return null;
            }
0
Comment
Question by:ba272
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
joechina earned 250 total points
ID: 17798245
Create a loop by yourself.
There is no Method to do it. And it's possible there are more than one keys having the same value.
0
 

Author Comment

by:ba272
ID: 17798269
right. thanks.
0
 

Author Comment

by:ba272
ID: 17798296
how best to iterate in a HashTable?
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 250 total points
ID: 17798358
Try something like:

          public string GetStreetDescriptor( string valueDescriptor )
          {
               if ( ContainsValue( valueDescriptor ) )              
               {
                   foreach (string key in this.Keys)
                   {
                       if (((string)this[key]) == valueDescriptor)
                           return (string)this[key];
                   }                    
               }
               return null;
          }
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now