Solved

Getting a key for the value, form a Hashtable

Posted on 2006-10-24
4
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

696 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