O'Reilly logo

Mastering Unity Scripting by Alan Thorn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

IEnumerable and IEnumerator

When you're working with collections of data, whether List, Dictionary, Stack, or others, you'll typically want to iterate (or traverse) all items in the list or at least some items, based on a specific criteria. In some cases, you'll want to loop through all items in sequence or some items. Most often, you'll want to traverse the items forwards in sequence, but as we've seen, there are times when reverse traversing is also suitable. You can loop through items using a standard for loop. However, this raises some annoyances that the interfaces of IEnumerable and IEnumerator can help us solve. Let's see what the annoyances are. Consider the for loop in the following code sample 6-5:

 //Create a total variable int Total ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required