假设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是按相应顺序的次数
那就用SortedList
foreach (DictionaryEntry id in ht)
{
Response.Write(id.Key + "||" + id.Value+"<br/>");
}
还要遍历啊那还是用2#的呢但我不了解SortedList ,请问具体是怎么去弄 ,详细代码怎么写?
xiexie
不想再循环了,本来数据很大了这是我自己想的
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的最大值只能自己设,
可以对键索引 效率不错
推荐使用
和Dictionary 相似