Create a name/value pair Array in C#?

I hail from the land of PHP where I could quite easily do something like this:

$highScores["Level 1"] = '1000';
$highScores["Level 2"] = '2000';
$highScores["Level 3"] = '3000';
$highScores["Level 4"] = '4000';

How can I achieve this in C#?

// With your using statements
using System.Collections.Generic;

// In your class
Dictionary<string, int> highScores;

void Awake() {
    highScores = new Dictionary<string, int>();
}

Search for the MSDN documentation on Dictionary<> and you’ll be good to go. Also, check out other Generics (List<>, Stack<>, and so on) for more fun. :slight_smile:

1 Like

I’ve managed to figure out how to use Dictionary

//Create a list of Speed Debuffs
Dictionary<string, float> speedDebuffs = new Dictionary<string, float>()
{
      {"Walk",.5f}
};

Thank you for your help.