日期:2014-05-18  浏览次数:20726 次

Hashtable的浅表复制问题,有懂的请进来一下
VB.NET code

        Dim Ahb As New Hashtable
        Dim Bhb As New Hashtable
        Ahb.Add("a", "aaaa")
        Ahb.Add("b", "bbbb")
        Ahb.Add("c", "cccc")
        Ahb.Add("d", "dddd")
        Bhb.Add("aa", "1111")
        Bhb.Add("bb", Ahb.Clone)
        Response.Write("Bhb.Item(0)===" & Bhb("bb")("b").ToString())



请问上面的程序怎样才能转成C#,谢谢

------解决方案--------------------
C# code

            System.Collections.Hashtable hash = new System.Collections.Hashtable();
            hash.Add("a", "aaaa");

------解决方案--------------------
Hashtable Ahb = new Hashtable();
Hashtable Bhb = new Hashtable();
Ahb.Add("a", "aaaa");
Ahb.Add("b", "bbbb");
Ahb.Add("c", "cccc");
Ahb.Add("d", "dddd");
Bhb.Add("aa", "1111");
Bhb.Add("bb", Ahb.Clone());
Response.Write("Bhb.Item[0]===" + Bhb["bb"]["b"].ToString());
------解决方案--------------------
探讨

C# code

System.Collections.Hashtable hash = new System.Collections.Hashtable();
hash.Add("a", "aaaa");

------解决方案--------------------
C# code
Hashtable Ahb = new Hashtable();
Hashtable Bhb = new Hashtable();
Ahb.Add("a", "aaaa");
Ahb.Add("b", "bbbb");
Ahb.Add("c", "cccc");
Ahb.Add("d", "dddd");
Bhb.Add("aa", "1111");
Bhb.Add("bb", Ahb.Clone());
Response.Write("Bhb.Item(0)===" + ((Hashtable)Bhb["bb"])["b"].ToString());

------解决方案--------------------
参看1楼写法,哈希表要引用空间的,不过直接打右键添加也是可以的,注意大小写