| Description |
|
Gets a read-only Ilist of all the Keys in the current SortedList. The interesting and very useful aspect to this list is that it is hot-linked to the SortedList : changes to the latter are immediately reflected in the IList.
|
|
| Microsoft MSDN Links |
System.Collections
System.Collections.SortedList
|
|
|
| Illustrating the dynamic nature of the returned Key list |
program Project1;
{$APPTYPE CONSOLE}
uses
System.Collections;
var
MyList : System.Collections.SortedList;
KeyList : System.Collections.IList;
i : Integer;
begin
// Create our sorted list
MyList := SortedList.Create;
// Add entries to the Source list
MyList['Name'] := 'Neil Moffatt';
MyList['Age'] := TObject(47);
MyList['Birthday'] := DateTime.Create(1957, 2, 18);
// Get a read only, dynamically updated list of keys
KeyList := MyList.GetKeyList;
// Display the key list :
Console.WriteLine('KeyList at the start :');
Console.WriteLine;
for i := 0 to KeyList.Count-1 do
Console.WriteLine(KeyList[i].ToString);
// Now add a couple of entries
MyList['Status'] := 'Single';
MyList['Gender'] := 'Male';
// Display the key list again :
Console.WriteLine;
Console.WriteLine('KeyList after updates :');
Console.WriteLine;
for i := 0 to KeyList.Count-1 do
Console.WriteLine(KeyList[i].ToString);
Console.Readline;
end.
| | Show full unit code | KeyList at the start :
Age
Birthday
Name
KeyList after updates :
Age
Birthday
Gender
Name
Status
|
| |
|
|
|