ISortedList.IndexOfKey

Syntax

IndexOfKey(Key: Variant): Integer;

Parameters

Key. Key of the element, which index should be obtained.

Description

The IndexOfKey method returns element index by key.

Comments

The method returns -1 if the element with the specified key is missing.

Example

Sub UserProc;
Var
    SortList: ISortedList;
    i: Integer;
Begin
    SortList := New SortedList.Create;
    For i := 0 To Math.RandBetweenI(50100Do
        SortList.Add("Key_" + Math.RandBetweenI(0100).ToString, "Number " + Math.RandBetweenI(0100).ToString);
    End For;
    i := SortList.IndexOfKey("Key_25");
End Sub UserProc;

After executing the example the "i" variable contains element index with the Key_25 key if it exists.

See also:

ISortedList