// The strongly typed collection class.
class Names extends LJCCollectionBase
{
// Adds a string.
// This method makes a string collection strongly typed.
public function Add(string $text)
{
$retItem = $this->AddItem($text);
return $retItem;
}
}
// Indicates if a key already exists.
private static function HasKey()
{
$names = new Names();
$names->Add("First");
$names->Add("Second");
$names->Add("Third");
$result = "";
foreach ($names as $name)
{
if (strlen($result) > 0)
{
$result .= ",";
}
$result .= $name;
}
// result:
// First,Second,Third;
}
|