本文介绍了如何在C#中加入8个哈希表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有八个哈希表ht1,ht2 ............. ht8所以我想在ht9中加载所有哈希表数据,这怎么可能。

I have eight hash table ht1,ht2.............ht8 so i want to load all hashtable data in a ht9 how can this possible.

推荐答案

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





以后您可以通过这样做获得h7对象





and later you can get h7 object by doing this

Hashtable tmpH7 = h9["h7"];


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


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;
    }
}



调用Merger()来合并哈希表:


Call Merger() to merger hash tables:

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);


这篇关于如何在C#中加入8个哈希表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 15:44