প্রথমে একত্রিত করার ডিকশনারিগুলো সেট করুন −
Dictionarydict1 = new Dictionary (); dict1.Add("one", 1); dict1.Add("Two", 2); Dictionary dict2 = new Dictionary (); dict2.Add("Three", 3); dict2.Add("Four", 4);
এখন, HashSet ব্যবহার করে একত্রিত করুন। একই উদ্দেশ্যে UnionWith() মেথডটি ব্যবহার করা হয় −
HashSethSet = new HashSet (dict1.Keys); hSet.UnionWith(dict2.Keys);
সম্পূর্ণ কোডটি নিচে দেওয়া হলো −
উদাহরণ
using System;
using System.Collections.Generic;
public class Program {
public static void Main() {
Dictionary dict1 = new Dictionary();
dict1.Add("one", 1);
dict1.Add("Two", 2);
Dictionary dict2 = new Dictionary();
dict2.Add("Three", 3);
dict2.Add("Four", 4);
HashSet hSet = new HashSet(dict1.Keys);
hSet.UnionWith(dict2.Keys);
Console.WriteLine("ডিকশনারির ইউনিয়ন...");
foreach(string val in hSet) {
Console.WriteLine(val);
}
}
}
আউটপুট
ডিকশনারির ইউনিয়ন... one Two Three Four