private static void DictionaryExample() { Dictionary <string, string> users = new Dictionary <string, string>(); bool adding = true; do { Tryagain: string username = MyConsole.getString("Enter a Username for UR login"); string pwd = MyConsole.getString("Enter the Password"); if (users.ContainsKey(username)) { Console.WriteLine("User already exists\nPlease try again"); goto Tryagain; } else { users[username] = pwd; } string choice = MyConsole.getString("Press A to add or any key to leave"); adding = choice.ToUpper() == "A" ? true : false; } while (adding); Console.WriteLine("Lets allow the user to log..."); string uname = MyConsole.getString("Enter a Username for UR login"); string upwd = MyConsole.getString("Enter the Password"); if (users.ContainsKey(uname)) { if (users[uname] == upwd) { Console.WriteLine("Welcome user!!!!"); } else { Console.WriteLine("Password is wrong!!!!"); } } else { Console.WriteLine("user name is wrong!!!!"); } }
private static void QueueExample() { Queue <string> recentItems = new Queue <string>(); do { string item = MyConsole.getstring("Enter the Item to view"); if (recentItems.Count == 3) { recentItems.Dequeue();//Removes the first item in the queue. } recentItems.Enqueue(item); Console.WriteLine("Ur recently viewed items:"); var iterator = recentItems.Reverse(); foreach (string obj in iterator) { Console.WriteLine(obj); } } while (true); }