Problem with Lists and Remove
Hey guys, I have a public list made of objects. Does objects have a name. Now i want to remove all objects from the list without an name. However this throws the exeption "invalidoperationexception collection was modified enumeration operation may not execute" however the object is there cus i can print its name or other aspects it has. What am i doing wrong?
this is the code:
public void RemoveUnnamed() {
foreach (Player player in players)
{
if (string.IsNullOrWhiteSpace(player.name))
{
print(player.name);
players.Remove(player);
}
}
}
Comment