Can anyone please help me to add number of strings to a hash table. Actually i am trying to make a "hangman game". I want to store the answers in a hash table but there's something wrong i my code <sorry!! I can't provide the code>.

Please suggest me a way to store the stringsin a hash table. If possible suggest a way to look for the right ansnwer in the hash table.

Thanks in advance.

using System;
using System.Collections.Generic;

// Creating and adding answers.
Dictionary<String, String> answers = new Dictionary<String, String> () {
    {"mykey1", "myanswer1"},
    {"mykey2", "myanswer2"}
};

// Adding on the fly.
answers.Add ("mykey3", "myanswer3");

// Retrieving answers.
String trykey = "mykey2";
String answer;
Boolean retrieved = answers.TryGetValue (trykey, out answer);
if (retrieved) {
    Console.WriteLine (
        String.Format ("Retrieved: {0}", answer));
} else {
    Console.WriteLine (
        String.Format ("Invalid key! Can't find an answer for: {0}", trykey));
}

I have no idea what your keys are supposed to be, so I chose String.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.