Time for action – create a dictionary of pony names and keys
Create a Dictionary
using type int
for the keys.
- Modify
LearningScript
as shown in the next screenshot. - Save the file.
- In Unity, click on Play.
What just happened?
Here is the output to Unity's Console.
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 aList
.A
Dictionary
requires you to specify the type for theKey
.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.