Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have eight hash table ht1,ht2.............ht8 so i want to load all hashtable data in a ht9 how can this possible.
Posted

Please help yourself by helping us, with a one liner question you are expecting us to read your mind, your hard disk, your screen and all :)

While just hitting in the dark a solution could be like, you can put all your hashtables h1..h8 in h9 as follows

Key "h1", value => h1 object reference

C#
Hashtable h9 = new Hashtable();
h9.Add("h1", h1);
....
h9.Add("h8", h8);


and later you can get h7 object by doing this

C#
Hashtable tmpH7 = h9["h7"];
 
Share this answer
 
Try like beow
C#
var ht2 = new Hashtable {{"B", "b"}};

var ht3 = new Hashtable {{"A", "z"}};
var ht4 = new Hashtable {{"C", "c"}};

var l = new List<hashtable> {ht1, ht2, ht4};
var d = new Dictionary<object, object>();

d = l.Aggregate(d, (current, t) => current.Union(t.Cast<dictionaryentry>().ToDictionary(a => a.Key, a => a.Value)).ToDictionary(b => b.Key, b => b.Value));

Hope this helps
 
Share this answer
 
v3
I might use the extension method to solve this problem:

C#
public static class Helper
{
    public static Hashtable Merger(this Hashtable ht, Hashtable ht1)
    {
        var e = ht1.GetEnumerator();
        while (e.MoveNext())
        {
            if (!ht.ContainsKey(e.Key))
                ht.Add(e.Key, e.Value);
        }
        return ht;
    }
}

Call Merger() to merger hash tables:
C#
Hashtable ht1 = new Hashtable();
Hashtable ht2 = new Hashtable();
Hashtable ht3 = new Hashtable();
ht1.Add("a", 1);
ht1.Add("b", 2);
ht2.Add("c", 3);
ht3.Add("d", 4);
Hashtable ht4 = ht1.Merger(ht2).Merger(ht3);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900