This might not be the best way of wording this question but it's kind of what I want to do.
I have a Dictionary that looks like this:
Dictionary<string, int> gameLookup = new Dictionary<string, int>();
"Empty Game Title 1", 99
"Super Metroid", 98
"Empty Game Title 2", 98
"Final Fantasy VI", 95
"Empty Game Title 3", 92
"Donkey Kong Country", 90
I have a List with a bunch of game names like this, with repetition:
List<string> gameNames = new List<string>();
"Super Mario Bros."
"Super Mario Bros."
"Super Mario Bros."
"Super Metroid"
"Super Metroid"
"Final Fantasy VI"
"Donkey Kong Country"
"Donkey Kong Country"
"Donkey Kong Country"
"Paper Mario"
"Paper Mario"
"The Legend of Zelda"
"The Legend of Zelda"
"The Legend of Zelda"
"Street Fighter"
What I would like to do is this, iterate through this massive games List, and use the gameLookup Dictionary
to assign a score. If the game from the massive games List doesn't exist in the gameLookup, use the 'Empty Game Title n' as the lookup key.
So, Paper Mario would technically be Empty Game 1, The Legend of Zelda would be Empty Game 2, and Street Fighter would be Empty Game 3.
I have tried doing a goto
but it doesn't seem to do anything.
Here's my approach:
public static int PerformLookup(List<string> GameNames, Dictionary<string, int> GameLookup)
{
Restart:
int reviewScore = 0;
int startingEmptyGameTitle = 1;
foreach (string element in GameNames)
if (GameLookup.ContainsKey(element))
reviewScore = GameLookup[element]
else
{
reviewScore = GameLookup["Empty Game Title " + startingEmptyGameTitle]
startingEmptyGameTitle++;
goto Restart;
}
return reviewScore;
}
The reason I think I need to do a goto
is because of the repetition. Because if Paper Mario is actually Empty Game Title 1, then without breaking out, it's going to assume the next iteration that is Paper Mario will be Empty Game Title 2, so I would want to keep breaking out but then restarting the loop so it remembers that Paper Mario -> Empty Game Title 1.
I hope that makes sense. This might not be the best approach so by all means, if you think there's a better way.