I want to store my player scores. I will have different worlds and worlds have different levels. Thats why i want something like..
public static void AddScore(int world, int level, int rolls, float time, float score)
{
_scores[world][level] = new LevelScore(rolls, time, score);
}
public static LevelScore GetScore(int world, int level)
{
if (_scores.ContainsKey(world))
{
var scoresOfWorld = _scores[world];
if(scoresOfWorld.ContainsKey(level))
{
return scoresOfWorld[level];
}
}
return new LevelScore();
}
I tried it with Dictionary inside a Dictionary..
public static Dictionary<int, Dictionary<int, LevelScore>> _scores = new Dictionary<int, Dictionary<int, LevelScore>>();
but AddScore(...) leads into "KeyNotFoundException: The given key was not present in the dictionary." I thought the key would be added if it is not existing. What is the best way for me to archive what i want easy?