when using foreach loop in Unity, I need to call this in the update method. Therefore, it is called once per frame ...
I want to know if it is better to check the counter before using the foreach loop or if it is redundant.
So, I have a
if (myList.Count > 0)
{
foreach (Type type in myList)
{
}
}
and
foreach (Type type in myList)
{
}
I could also use
for (int i = 0; i < myList.Count; i++)
{
myList[i].DoSomething();
}
source
share