Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

Getting a key for the value, form a Hashtable

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
ba272
Asked:
ba272
  • 2
2 Solutions
 
joechinaCommented:
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
 
ba272Author Commented:
right. thanks.
0
 
ba272Author Commented:
how best to iterate in a HashTable?
0
 
Carl TawnSystems and Integration DeveloperCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now