Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting a key for the value, form a Hashtable

Posted on 2006-10-24
4
Medium Priority
?
228 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 1000 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 1000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

636 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