Hashtable ContainsValue
In this chapter you will learn:
Value existance
We can use the ContainsValue() method to check if Hashtable contains a value.
using System;/*from ja v a 2 s. c om*/
using System.Collections;
class MainClass
{
public static void Main()
{
Hashtable myHashtable = new Hashtable();
myHashtable.Add("AL", "Alabama");
myHashtable.Add("CA", "California");
myHashtable.Add("FL", "Florida");
myHashtable.Add("NY", "New York");
myHashtable.Add("WY", "Wyoming");
foreach (string myKey in myHashtable.Keys)
{
Console.WriteLine("myKey = " + myKey);
}
foreach(string myValue in myHashtable.Values)
{
Console.WriteLine("myValue = " + myValue);
}
if (myHashtable.ContainsValue("Florida"))
{
Console.WriteLine("myHashtable contains the value Florida");
}
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Collections