Guest User

Dictionary<> Issue

a guest
Jul 18th, 2022
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Sys = Cosmos.System;
  5.  
  6. namespace CosmosKernel1
  7. {
  8.     public class Kernel : Sys.Kernel
  9.     {
  10.         public Dictionary<string, bool> alphabet = new Dictionary<string, bool>()
  11.         {
  12.             //none of these queries work
  13.             //I originally added the entire alphabet because I thought its was an issue with certain characters
  14.             {"a", true},
  15.             {"b", true},
  16.             {"c", true},
  17.             {"d", true},
  18.             {"e", true},
  19.             {"f", true},
  20.             {"g", true},
  21.             {"h", true},
  22.             {"i", true},
  23.             {"j", true},
  24.             {"k", true},
  25.             {"l", true},
  26.             {"m", true},
  27.             {"n", true},
  28.             {"o", true},
  29.             {"p", true},
  30.             {"q", true},
  31.             {"r", true},
  32.             {"s", true},
  33.             {"t", true},
  34.             {"u", true},
  35.             {"v", true},
  36.             {"w", true},
  37.             {"x", true},
  38.             {"y", true},
  39.             {"z", true},
  40.             {"power", true},
  41.             {"del", true},
  42.             //these queries work though
  43.             {"powers", true},
  44.             {"blue", true},
  45.             {"rm", true},
  46.             {"list", true},
  47.             {"pwer", true},
  48.             {"..", true}
  49.         };
  50.  
  51.         protected override void BeforeRun()
  52.         {
  53.             Console.Clear();
  54.             Console.WriteLine("Input a string to see if it is recognized in the dictionary.");
  55.         }
  56.  
  57.         protected override void Run()
  58.         {
  59.             Console.Write("Input> ");
  60.             string key = Console.ReadLine();
  61.             Console.WriteLine($"Input Key \"{key}\" is in the dictionary: {alphabet.ContainsKey(key).ToString()}");
  62.             //to confirm that key "a" is in the dictionary if a is the input
  63.             if (key == "a")
  64.             {
  65.                 Console.WriteLine("String Key \"a\" is in the Dictionary: " + alphabet.ContainsKey("a").ToString());
  66.                 if (alphabet.ContainsKey("a"))
  67.                 {
  68.                     Console.WriteLine("Key \"a\" value in dictionary: " + alphabet["a"].ToString());
  69.                 }
  70.             }
  71.         }
  72.     }
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment