Skip to content

Comparsion

Azharunissa Khan

Asked Jan 23, 2014, 9:22 PM EST1 answer
Share
LinkedInX
I came across a small problem.I have a hash table code in which the "KEY" field contains words/strings instead of numbers.Mean while i have a html/apsx page with a "TEXT BOX" field where i give some words as input.Now the task is to compare the words given as input by me and the words in that exist hash table.The matched words data in hash table are to retrieved as output(In other words ,if any match found ,the values in the "VALUE" field of the hash table are to be retrieved).
Could you please provide me a code?
Or else could you please suggest me a way so i could work on it?
Thank you !!

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Biswa Pujarini Mohapatra
    0
    I hope this is what you are looking for example

    C#
     static Hashtable GetHashtable()
            {
                // Create and return new Hashtable.
                Hashtable hashtable = new Hashtable();
                hashtable.Add("one", "test");
                hashtable.Add("two", 55);
                hashtable.Add("three", 540);
                return hashtable;
            }


    Code
    private void button1_Click(object sender, EventArgs e)
            {
                Hashtable hashtable = GetHashtable();
    
    
                foreach (DictionaryEntry item in hashtable)
                {
                    if (item.Key.Equals(textBox1.Text.Trim()))
                    {
    
    
                        MessageBox.Show(item.Value.ToString());
                    }
                }
            }
    0