C# Hashtable Contains
Description
Hashtable Contains
determines whether the Hashtable
contains a specific key.
Syntax
Hashtable.Contains
has the following syntax.
public virtual bool Contains(
Object key
)
Parameters
Hashtable.Contains
has the following parameters.
key
- The key to locate in the Hashtable.
Returns
Hashtable.Contains
method returns true if the Hashtable contains an element with the specified key; otherwise,
false.
Example
The following example shows how to determine whether the Hashtable contains a specific element.
//from w w w.j a v a 2 s. c o m
using System;
using System.Collections;
public class SamplesHashtable {
public static void Main() {
Hashtable myHT = new Hashtable();
myHT.Add( 0, "zero" );
myHT.Add( 1, "one" );
myHT.Add( 2, "two" );
myHT.Add( 3, "three" );
myHT.Add( 4, "four" );
Console.WriteLine(myHT.Contains( 2 ));
Console.WriteLine(myHT.ContainsKey( 2 ));
Console.WriteLine(myHT.ContainsValue( "two" ));
}
}
The code above generates the following result.