Home  |  Delphi .net Home  |  System.Collections.ArrayList  |  Contains Method
Contains  
Method  
Searches the sorted ArrayList for a specific element
ArrayList Class
System.Collections NameSpace
CF1.  Function Contains ( Needle : Object; ) : Boolean;
CF : Methods with this mark are Compact Framework Compatible
Description
The current ArrayList is scanned for a match with the Needle object value.
 
The search does not look for the object instance - it merely scans the ArrayList, using the principle object value as the comparison value, returning true if found, otherwise false.
Microsoft MSDN Links
System.Collections
System.Collections.ArrayList
 
 
A simple example of found and not found elements
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  List  : System.Collections.ArrayList;

begin
  // Create our array list object
  List := ArrayList.Create;

  // Fill it
  List.Add('ABC');
  List.Add('DEF');
  List.Add('GHI');
  List.Add('JKL');
  List.Add('MNO');

  // Try to find 'GHI'
  if List.Contains('GHI')
  then Console.WriteLine('''GHI'' found')
  else Console.WriteLine('''GHI'' not found');

  // Try to find 'ghi'
  if List.Contains('ghi')
  then Console.WriteLine('''ghi'' found')
  else Console.WriteLine('''ghi'' not found');

  Console.Readline;
end.
Show full unit code
  'GHI' found
  'ghi' not found
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author