Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
C# | Check if the Hashtable contains a specific Key
Next article icon

C# | Check if the Hashtable contains a specific Value

Last Updated : 01 Feb, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. The key is used to access the items in the collection. Hashtable.ContainsValue(Object) Method is used to check whether the Hashtable contains a specific value or not. Syntax:
  public virtual bool ContainsValue(object value);  
Parameter:
value: The value of type System.Object to locate in the Hashtable. The value can be null.
Return Type: This method returns true if the Hashtable contains an element with the specified value otherwise it returns false. The return type of this method is System.Boolean. Below given are some examples to understand the implementation in a better way: Example 1: CSHARP
// C# code to check if the HashTable // contains a specific Value using System; using System.Collections;  class GFG {      // Driver code     public static void Main()     {          // Creating a Hashtable         Hashtable myTable = new Hashtable();          // Adding elements in Hashtable         myTable.Add("g", "geeks");         myTable.Add("c", "c++");         myTable.Add("d", "data structures");         myTable.Add("q", "quiz");          // check if the HashTable contains         // the required Value or not.         if (myTable.ContainsValue("c++"))             Console.WriteLine("myTable contains the Value");         else             Console.WriteLine("myTable doesn't contain the Value");     } } 
Output:
  myTable contains the Value  
Example 2: CSHARP
// C# code to check if the HashTable // contains a specific Value using System; using System.Collections;  class GFG {      // Driver code     public static void Main()     {          // Creating a Hashtable         Hashtable myTable = new Hashtable();          // Adding elements in Hashtable         myTable.Add("India", "Country");         myTable.Add("Chandigarh", "City");         myTable.Add("Mars", "Planet");         myTable.Add("China", "Country");          // check if the HashTable contains         // the required Value or not.         if (myTable.ContainsKey("Ocean"))             Console.WriteLine("myTable contains the Value");         else             Console.WriteLine("myTable doesn't contain the Value");     } } 
Output:
  myTable doesn't contain the Value  
Reference:
  • https://docs.microsoft.com/en-us/dotnet/api/system.collections.hashtable.containsvalue?view=netframework-4.7.2

Next Article
C# | Check if the Hashtable contains a specific Key

S

Sahil_Bansall
Improve
Article Tags :
  • Misc
  • C#
  • CSharp-method
  • CSharp-Collections-Hashtable
  • CSharp-Collections-Namespace
Practice Tags :
  • Misc

Similar Reads

  • C# | Check if the Hashtable contains a specific Key
    The Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. The key is used to access the items in the collection. Hashtable.ContainsKey(Object) Method is used to check whether the Hashtable contains a specific key or not. Syntax: public v
    2 min read
  • C# | Check whether a Hashtable contains a specific key or not
    Hashtable.Contains(Object) Method is used to check whether the Hashtable contains a specific key or not. Syntax: public virtual bool Contains (object key); Here, key is the Key of Object type which is to be located in the Hashtable. Return Value: This method returns true if the Hashtable contains an
    2 min read
  • C# | Check if a HashSet contains the specified element
    A HashSet is an unordered collection of the unique elements. It is found in System.Collections.Generic namespace. It is used in a situation where we want to prevent duplicates from being inserted in the collection. As far as performance is concerned, it is better in comparison to the list. HashSet.C
    2 min read
  • C# | Check if the StringDictionary contains a specific value
    StringDictionary.ContainsValue(String) method is used to check whether the StringDictionary contains a specific value or not. Syntax: public virtual bool ContainsValue (string value); Here, value is the value to locate in the StringDictionary. The value can be null. Return Value: The method returns
    2 min read
  • C# | Check if the SortedSet contains a specific element
    SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.Contains(T) Method is used to check if a SortedSet contains a specific element or not. Properties: In C#, SortedSet class can be used to store, remov
    2 min read
  • C# | Check if a SortedList object contains a specific value
    SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.ContainsValue(Object) method is used to check whether a SortedList o
    2 min read
  • C# | Gets an ICollection containing the values in the Hashtable
    Hashtable.Values Property is used to get an ICollection containing the values in the Hashtable. Syntax: public virtual System.Collections.ICollection Values { get; } Return Value: This property returns an ICollection containing the values in the Hashtable. Note: The order of values in the ICollectio
    2 min read
  • C# | Check if Hashtable has a fixed size
    Hashtable.IsFixedSize Property is used to get a value which indicates whether the Hashtable has a fixed size or not. Syntax: public virtual bool IsFixedSize { get; } Return Value: This property returns true if the Hashtable has a fixed size otherwise it returns false. The default is false. Below pro
    2 min read
  • C# | Check if HashSet and the specified collection contain the same elements
    Here's an example code that demonstrates how to use the Overlaps method to check if a HashSet and a specified collection share common elements in C#: C/C++ Code using System; using System.Collections.Generic; class Program { static void Main(string[] args) { // Create a HashSet and a List HashSet
    3 min read
  • C# | How to get hash code for the specified key of a Hashtable
    Hashtable.GetHash(Object) method is used to get the hashcode of the specified key of a Hashtable object. This method is inherited from the Object Class. Syntax: protected virtual int GetHash(Object Key); Exception: This method will give NullReferenceException if the key is null. Below programs illus
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences