Menu
Coddy logo textTech

Recap - HashSet

Part of the Logic & Flow section of Coddy's C# journey — lesson 61 of 66.

challenge icon

Challenge

Easy

Create a method named ProcessHashSet that performs multiple operations on a HashSet:

  1. Create a new HashSet of strings
  2. Add three fruit names: "Apple", "Banana", and "Orange"
  3. Print whether "Mango" exists in the set (use the format: "Contains Mango: True/False")
  4. Try to add "Apple" again and print whether it was added (use the format: "Added Apple again: True/False")
  5. Remove "Banana" and print whether it was successfully removed (use the format: "Removed Banana: True/False")
  6. Print the current count of elements (use the format: "Count: N")
  7. Return the HashSet

Try it yourself

using System;
using System.Collections.Generic;

class Program
{
    public static HashSet<string> ProcessHashSet()
    {
        // Write your code here
        return null;
    }
    
    static void Main(string[] args)
    {
        HashSet<string> result = ProcessHashSet();
        
        if (result != null)
        {
            Console.WriteLine(string.Join(", ", result));
        }
    }
}

All lessons in Logic & Flow