假设mc的值为:aa,vv,dds,dfds,fdsfgds,fds,fd,
string[] sArray = Regex.Split(mc, ",", RegexOptions.IgnoreCase);
            Hashtable ht = new Hashtable();
          
            foreach (string i in sArray)
                if (i.ToString().Length > 0)
                {
                ht.Add(i.ToString(), i.ToString());
                 
                }我想请教下怎么让ht得到数据组里面的Value , Key 值是i.ToString() 和相应位置的数字
如:
aa,0 
vv ,1
fds ,6是按相应顺序的次数        

解决方案 »

  1.   

    想按键索引 又想按下标索引
    那就用SortedList 
      

  2.   

    数据放到hashtable里面以后,你可以遍历一次hashtable
     foreach (DictionaryEntry id in ht)
            {
                Response.Write(id.Key + "||" + id.Value+"<br/>");
            }
      

  3.   


    还要遍历啊那还是用2#的呢但我不了解SortedList ,请问具体是怎么去弄 ,详细代码怎么写?
    xiexie
      

  4.   

    再加一个hastable, key 和 value反过来放
      

  5.   

    你还是要循环一次,判断key值然后返回value可以了。
      

  6.   

    你还是要循环一次,判断key值然后返回value可以了。
      

  7.   

    不会吧
    不想再循环了,本来数据很大了这是我自己想的
     string[] sArray = Regex.Split(mc, ",", RegexOptions.IgnoreCase);            Hashtable ht = new Hashtable();            for (int i = 0; i < 10; i++)
                {
                    if (sArray[i].ToString().Length > 0)
                    {
                                           ht.Add(sArray[i].ToString(), i);
                    }
                }
                this.gvProduct.DataSource =ht;
                this.gvProduct.DataBind();但有个新问题:能否统计sArray中的个数啊 我那个i的最大值只能自己设,
      

  8.   

    谁能告诉我一个简单的方法吗如用用SortedList 实现  改怎么写
      

  9.   

    SortedList 
    可以对键索引 效率不错 
    推荐使用
    和Dictionary 相似