Difference between revisions of "DisplayTileValues"
m |
m |
||
Line 20: | Line 20: | ||
etc... | etc... | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | This code could be improved, as it is given access to the string list of allowed words, but doesn't need to use this list. | ||
This is quite the simple method, but I'll explain it nonetheless. The method loops through each KeyValuePair in the TileDictionary; A Dictionary which if u recall stores the character point associations of the program. Note when iterating through a dictionary u don't iterate through the value or the keys but u instead recieve an association between the two in a datatype struct KeyValuePair<TKey, TValue>. To access the key from this struct u simple use object notation and the identifier Key and for the value u use the same and identifier Value. Once the iteration has begon, the program outputs the character (the key) and it's corresponding point score (the value). | This is quite the simple method, but I'll explain it nonetheless. The method loops through each KeyValuePair in the TileDictionary; A Dictionary which if u recall stores the character point associations of the program. Note when iterating through a dictionary u don't iterate through the value or the keys but u instead recieve an association between the two in a datatype struct KeyValuePair<TKey, TValue>. To access the key from this struct u simple use object notation and the identifier Key and for the value u use the same and identifier Value. Once the iteration has begon, the program outputs the character (the key) and it's corresponding point score (the value). |
Latest revision as of 13:43, 14 November 2017
private static void DisplayTileValues(Dictionary<char, int> TileDictionary, List<string> AllowedWords)
{
Console.WriteLine();
Console.WriteLine("TILE VALUES");
Console.WriteLine();
foreach (var Tile in TileDictionary)
{
Console.WriteLine("Points for " + Tile.Key + ": " + Tile.Value);
}
Console.WriteLine();
}
This code displays the point value associated with each tile in the tile dictionary to a user, in the following format:
TILE VALUES
Points for A: 1
Points for B: 3
etc...
This code could be improved, as it is given access to the string list of allowed words, but doesn't need to use this list.
This is quite the simple method, but I'll explain it nonetheless. The method loops through each KeyValuePair in the TileDictionary; A Dictionary which if u recall stores the character point associations of the program. Note when iterating through a dictionary u don't iterate through the value or the keys but u instead recieve an association between the two in a datatype struct KeyValuePair<TKey, TValue>. To access the key from this struct u simple use object notation and the identifier Key and for the value u use the same and identifier Value. Once the iteration has begon, the program outputs the character (the key) and it's corresponding point score (the value).