Game Development Reference
In-Depth Information
The foreach keyword
C# iterators use
foreach
instead of
for
. Also notice the variable declaration within the
for/foreach
statement in the following code. C# requires the type of the item con-
tained in the list to be explicitly declared:
// JavaScript user:
for (var item in itemList) {
item.DoSomething();
}
// C# user:
foreach (ItemType item in itemList) {
item.DoSomething();
}