Solved

Getting a key for the value, form a Hashtable

Posted on 2006-10-24
4
221 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

21 Experts available now in Live!

Get 1:1 Help Now