How to add numbers to HashSet in C#

1 Answer

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

class Program
{
    static void Main() {
        HashSet<int> hs = new HashSet<int>();
        
        for (int i = 0; i < 5; i++) {
            hs.Add(i * 3);
        }
        
        foreach (int item in hs) {
            Console.Write("{0}{1}", item, " ");
        }
    }
}



/*
run:

0 3 6 9 12 

*/

 



answered Oct 28, 2019 by avibootz

Related questions

1 answer 148 views
1 answer 114 views
114 views asked Feb 7, 2024 by avibootz
1 answer 115 views
115 views asked Mar 9, 2023 by avibootz
1 answer 136 views
136 views asked Jul 18, 2022 by avibootz
2 answers 152 views
1 answer 122 views
122 views asked Dec 13, 2020 by avibootz
...