Home  |  Delphi .net Home  |  System.Collections.HashTable  |  Contains Method
  
Contains  
Method  
Returns true if the current HashTable contains the given Key
HashTable Class
System.Collections NameSpace
CF1.  Function Contains ( Key : Object ) : Boolean;
CF : Methods with this mark are Compact Framework Compatible
Description
The Contains method searches the current HashTable for an entry matching Key, returning true if found, otherwise false.
Microsoft MSDN Links
System.Collections
System.Collections.HashTable
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
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['Birthday'] := DateTime.Create(1957, 2, 18);
  MyTable['Age']      := TObject(47);

  // 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.Contains('Age')
  then Console.WriteLine('MyTable contains key ''Age''')
  else Console.WriteLine('MyTable does not contain key ''Age''');

  if MyTable.Contains('AGE')
  then Console.WriteLine('MyTable contains key ''AGE''')
  else Console.WriteLine('MyTable does not contain key ''AGE''');

  Console.Readline;
end.
   MyTable at the start :
  
   Birthday = 18/02/1957 00:00:00
   Age = 47
   Name = Neil Moffatt
  
   MyTable contains key 'Age'
   MyTable does not contain key 'AGE'
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author