我有一个哈希表,他的value是这样的object.Tittle,都是有.的,我想把.两边的字符放进string数组
比如string[0]=object,string[1]=Tittle,string[2]=object1,string[3]=Tittle1...........

解决方案 »

  1.   

            object[] a = new object[30];
            
            Hashtable ht = new Hashtable();
            ht.Add("a", "a1");
            ht.Add("b", "b1");
            ht.Add("c", "c1");
            ht.CopyTo(a, 0);
            //转为string
            string[] s = Array.ConvertAll<object, string>(a, delegate(object o) { return o == null ? "" : o.ToString(); });
      

  2.   

    不是简单的哈希表转字符数组的,我是要获取。两边的字符串,然后放进字符数组foreach(var o in ht)
    {
       string[] arr=o.ToString().Split('.');
    }这样写只是获取了哈希表当前的值放进了数组,没有把整个都放进去,求解
      

  3.   


            Hashtable ht = new Hashtable();
            ht.Add("a", "a1");
            ht.Add("b", "b1");
            ht.Add("c", "c1");
            string[] s = new string[30];
            ArrayList keyList = new ArrayList(ht.Keys);
            ArrayList valueList = new ArrayList(ht.Values);
            for (int i = 0; i < keyList.Count; i++)
            {
                s[i * 2] = keyList[i].ToString();
                s[i * 2 + 1] = valueList[i].ToString();
            }
      

  4.   

    不是这样的哦,ht是这样的
    ht.Add("a","object.Tittle")
    ht.Add("b","object1.Tittle1")
    放进数组的是s[0]="object";s[1]="Tittle"...........
    是把ht的“值”截取了放数组,和Key没关系
      

  5.   

    System.Collections.Generic.List<string> s = new System.Collections.Generic.List<string>();
            Hashtable ht = new Hashtable();
            ht.Add("a", "object.Tittle");
            ht.Add("b", "object1.Tittle1");
            foreach (DictionaryEntry v in ht)
            {
                foreach (string ss in v.Value.ToString().Split('.'))
                {
                    s.Add(ss);
                }
            }
      

  6.   

    如果你想要string[]类型s.ToArray()就行了