On Monday, 13 April 2020 at 04:21:48 UTC, Leonardo wrote:

 foreach (ref gi; GameItems)
{
    if (gi == Weapon)
        gi.Attack()
}

How would it be?

Replying myself...

weapon = cast(Weapon) gi;
if (weapon !is null)
    weapon.Attack()

can be simplified as:

    if (auto weapon = cast(Weapon) gi)
        weapon.Attack();

Reply via email to