Home  |  Delphi .net Home  |  System.Collections.HashTable  |  ContainsValue Method
ContainsValue  
Method  
Returns true if the current HashTable contains the given Value
HashTable Class
System.Collections NameSpace
CF1.  Function ContainsValue ( Value : Object; ) : Boolean;
CF : Methods with this mark are Compact Framework Compatible
Description
The ContainsValue method searches the current HashTable for an entry matching Value, returning true if found, otherwise false.
Microsoft MSDN Links
System.Collections
System.Collections.HashTable
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  MyTable    : System.Collections.HashTable;
  DictEntry  : DictionaryEntry;
  Enumerator : IEnumerator;

begin
  // Create our hash table
  MyTable := HashTable.Create;

  // Add entries to it
  MyTable['Name']    := 'Neil Moffatt';
  MyTable['Manager'] := 'Steven Hemingway';
  MyTable['Mentor']  := 'Danny Thorpe';

  // Display the table contents
  Console.WriteLine('MyTable at the start :');
  Console.WriteLine;
  Enumerator := MyTable.GetEnumerator;
  while Enumerator.MoveNext do
  begin
    // Note that entries are returned in key sorted order
    DictEntry := DictionaryEntry(Enumerator.Current);
    Console.WriteLine('{0} = {1}',
                      DictEntry.Key.ToString,
                      DictEntry.Value.ToString);
  end;

  Console.WriteLine;

  if MyTable.ContainsValue('Steven Hemingway')
  then Console.WriteLine('''Steven Hemingway'' value found')
  else Console.WriteLine('''Steven Hemingway'' value not found');

  if MyTable.ContainsValue('Born Borg')
  then Console.WriteLine('''Born Borg''        value found')
  else Console.WriteLine('''Born Borg''        value not found');

  Console.Readline;
end.
Show full unit code
  MyTable at the start :
  
  Manager = Steven Hemingway
  Name = Neil Moffatt
  Mentor = Danny Thorpe
  
  'Steven Hemingway' value found
  'Born Borg'        value not found
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author