Time for action – using foreach loops to retrieve data

We're going to create an array, a list and a dictionary, then loop through each one to retrieve the desired data from each one by using foreach loops.

  1. Modify LearningScript as shown in the next screenshot.
  2. Save the file.
  3. In Unity, click on Play.
    Time for action – using foreach loops to retrieve data

What just happened?

As we looped through each list, we decided which data to display to the Console:

What just happened?

The analysis of the code is as follows:

For each list we created, we populated them using a Collection Initializer.

  • The code between lines 9 and 10 with its ...

Get Learning C# by Developing Games with Unity 3D Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.