Time for action – create a dictionary of pony names and keys

Create a Dictionary using type int for the keys.

  1. Modify LearningScript as shown in the next screenshot.
  2. Save the file.
  3. In Unity, click on Play.
    Time for action – create a dictionary of pony names and keys

What just happened?

Here is the output to Unity's Console.

What just happened?

The analysis of code is as follows:

  • The code on line 8 is as follows:
    Dictionary<int, string> myFavoritePonies = new Dictionary<int, string>();

    Declaring a Dictionary is very similar to declaring a List.

    A Dictionary requires you to specify the type for the Key.

    This example used integers for the ...

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.