C# Practice Exercises

Unique Tags with HashSet

Normalize and deduplicate tags.

Introduction

HashSet<T> expresses uniqueness directly and supports fast membership tests.

A case-insensitive comparer prevents differently cased spellings from becoming separate tags.

See how it works

Pick an operation to highlight its result in the diagram. Add a value that is already in the set to see that duplicates are ignored.

Runnable C# example

C#
Run code →
Program.cs
using System;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        var tags = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "C#", "dotnet", "c#" };
        Console.WriteLine(tags.Count);
    }
}
Result of running the code
2

Practice with the debugger

Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.

Practice with a challenge

Use what this lesson covers to solve a real problem. Each challenge runs in your browser with instant tests and an AI review.

All challenges