How to check if a hashtable contains a key in C#

2 Answers

0 votes
using System;
using System.Collections;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Hashtable hashtable = new Hashtable();

            hashtable.Add("c#", 100);
            hashtable.Add("c", 101);
            hashtable.Add("c++", 102);
            hashtable.Add("java", 107);

            if (hashtable.ContainsKey("c++"))
                Console.WriteLine("yes");
            else
                Console.WriteLine("no");
        }
    }
}


/*
run:
     
yes
 
*/

 



answered Feb 19, 2017 by avibootz
0 votes
using System;
using System.Collections;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Hashtable hashtable = new Hashtable();

            hashtable.Add("c#", 100);
            hashtable.Add("c", 101);
            hashtable.Add("c++", 102);
            hashtable.Add("java", 107);

            if (hashtable.Contains("c#"))
                Console.WriteLine("yes");
            else
                Console.WriteLine("no");
        }
    }
}


/*
run:
     
yes
 
*/

 



answered Feb 19, 2017 by avibootz

Related questions

1 answer 173 views
1 answer 168 views
1 answer 177 views
177 views asked Feb 20, 2017 by avibootz
1 answer 169 views
1 answer 160 views
...