The HashSet Class


A hash set is an unordered set in memory. The key is embedded within the element. A hash set of T is denoted in generic notation as HashSet<T>. An example of a hash set is shown below.

// Calculus -- HashSet -- A Simple Example

using System;
using Calculus;

class HashSets
{
    public static void Main()
    {
        try
        {
            HashSet<int> set = new HashSet<int>();

            set.Add(1);
            set.Add(2);
            set.Add(3);
            set.Add(4);
            set.Add(5);

            Console.WriteLine(set);
        }
        catch (Exception e) { Console.WriteLine("{0}", e); }
    }
}

The output of this program is shown below.

{1,2,3,4,5}