Home  |  Delphi .net Home  |  System.Collections.SortedList  |  ContainsValue Method
ContainsValue  
Method  
Returns true if the current SortedList contains the given Value
SortedList 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 SortedList for an entry matching Value, returning true if found, otherwise false.
Microsoft MSDN Links
System.Collections
System.Collections.SortedList
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  MyList     : System.Collections.SortedList;
  DictEntry  : DictionaryEntry;
  Enumerator : IEnumerator;

begin
  // Create our sorted list
  MyList := SortedList.Create;

  // Add entries to the Source list
  MyList['Name']    := 'Neil Moffatt';
  MyList['Manager'] := 'Steven Hemingway';
  MyList['Mentor']  := 'Danny Thorpe';

  // Display the Sorted list
  Enumerator := MyList.GetEnumerator;
  while Enumerator.MoveNext do
  begin
    DictEntry := DictionaryEntry(Enumerator.Current);
    Console.WriteLine('{0} = {1}',
                      DictEntry.Key.ToString,
                      DictEntry.Value.ToString);
  end;

  Console.WriteLine;

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

  if MyList.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
  Manager = Steven Hemingway
  Mentor = Danny Thorpe
  Name = Neil Moffatt
  
  'Steven Hemingway' value found
  'Born Borg'        value not found
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author