
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# Program to find a value in a Hashtable
Set Hahtable collection with elements.
Hashtable h = new Hashtable(); h.Add(1, "Jack"); h.Add(2, "Henry"); h.Add(3, "Ben"); h.Add(4, "Chris");
Let’s say now you need to find a value, then use the ContainsValue() method.
We are finding value “Chris” here −
h.ContainsValue(“Chris”);
Example
using System; using System.Collections; public class Demo { public static void Main() { Hashtable h = new Hashtable(); h.Add(1, "Jack"); h.Add(2, "Henry"); h.Add(3, "Ben"); h.Add(4, "Chris"); Console.WriteLine("Keys and Values list:"); foreach (var key in h.Keys ) { Console.WriteLine("Key = {0}, Value = {1}",key , h[key]); } Console.WriteLine("Value Chris exists? "+h.ContainsValue("Chris")); Console.WriteLine("Value Tom exists? "+h.ContainsValue("Tom")); } }
Output
Keys and Values list: Key = 4, Value = Chris Key = 3, Value = Ben Key = 2, Value = Henry Key = 1, Value = Jack Value Chris exists? True Value Tom exists? False
- Related Articles
- C# Program to find a key in a Hashtable
- C# Program to Check if Value exists in Hashtable
- C# Program to Get Key based on Value in Hashtable Collection
- C# Program to Replace Items in One Hashtable with Another Hashtable
- Check if the Hashtable contains a specific value in C#
- Check if a Hashtable is equal to another Hashtable in C#
- C# Program to Check a HashTable collection is empty or not
- Clear a Hashtable in C#
- C++ Program to Find ASCII Value of a Character
- JavaScript Program to Find a triplet that sum to a given value
- C# Program to Merge Two Hashtable Collections
- How to Create a HashTable Collection in C#?
- 8086 program to find the min value in a given array
- Program to find largest color value in a directed graph in Python
- Find a Fixed Point (Value equal to index) in a given array in C++ Program

Advertisements