How to declare and initialize a set containing unique objects in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;

class Program
{
    static void Main() {
        HashSet<string> hs = new HashSet<string>();
        
        hs.Add("a");
        hs.Add("b");
        hs.Add("c");
        hs.Add("d");

        foreach (var element in hs) {
            Console.WriteLine(element);
        }
    }
}




/*
run:

a
b
c
d

*/

 



answered Mar 11, 2023 by avibootz

Related questions

...