Difference between revisions of "DisplayTileValues"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "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 c...")
 
Line 1: Line 1:
 +
<syntaxhighlight lang=csharp>
 +
        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();
 +
        }
 +
</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:48, 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 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).