Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to combine dictionary keys in C#

1 Answer

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

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, int> dic1 = new Dictionary<string, int>();
            dic1.Add("aaa", 1);
            dic1.Add("bbb", 2);

            Dictionary<string, int> dic2 = new Dictionary<string, int>();
            dic2.Add("ccc", 3);
            dic2.Add("ddd", 4);
            dic2.Add("eee", 5);

            Dictionary<string, int> dic3 = new Dictionary<string, int>();
            dic3.Add("fff", 6);
            dic3.Add("ggg", 7);
            dic3.Add("hhh", 8);
            dic3.Add("iii", 9);

            HashSet<string> hashset = new HashSet<string>(dic1.Keys);
            hashset.UnionWith(dic2.Keys);
            hashset.UnionWith(dic3.Keys);

            foreach (string s in hashset)
                Console.WriteLine(s);
        }
    }
}


/*
run:

aaa
bbb
ccc
ddd
eee
fff
ggg
hhh
iii

*/

 



answered Mar 6, 2017 by avibootz
...