Difference between revisions of "DisplayTileValues"
m |
m |
||
Line 14: | Line 14: | ||
This code displays the point value associated with each tile in the tile dictionary to a user, in the following format: | This code displays the point value associated with each tile in the tile dictionary to a user, in the following format: | ||
+ | <syntaxhighlight lang=csharp> | ||
TILE VALUES | TILE VALUES | ||
Points for A: 1 | Points for A: 1 | ||
Points for B: 3 | Points for B: 3 | ||
etc... | etc... | ||
+ | </syntaxhighlight> | ||
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). |
Revision as of 13:40, 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 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).