Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Hashset()
- {
- HashSet<string> quizWords = new HashSet<string>();
- for (int i = 0; i < 10; i++)
- {
- Console.Write("Please type a word: ");
- string word = Console.ReadLine();
- if (quizWords.Contains(word))
- {
- Console.Write("Error: Word already added. ");
- }
- else
- {
- quizWords.Add(word);
- Console.Write("Word added. ");
- }
- }
- Console.Clear();
- while (quizWords.Count > 0)
- {
- Console.Write("Guess a word: ");
- string guess = Console.ReadLine();
- if (quizWords.Contains(guess))
- {
- quizWords.Remove(guess);
- Console.WriteLine($"Correct \"{guess}\" removed");
- }
- else
- {
- Console.WriteLine("Word not found. Try again.");
- }
- Console.WriteLine();
- }
- Console.WriteLine("All words guessed. Congratulations.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement