AllEnemies Is a list of type CAR and Contains Two types, Enemy and AiCar that Both inherit from the class named CAR. I would like to only do a specific action on the type Enemy.
How do you translate this Foreach Loop into a For loop as i would like to remove elements from the list whilst iterating over it.
foreach (Enemy TheEnemy in AllEnemies.OfType<Enemy>())
{
TheEnemy.ReturnToCache();
AllEnemies.Remove(TheEnemy);
}
If possible, i would like the code to be clean and Future proof. Meaning no If(TheEnemy.gettype == “Enemy”) ETC