var ht = new Hashtable {{"1", "a"}, {"d", "2"}, {"a", "1"}, {"c", "3"}};
foreach (DictionaryEntry entry in ht)
{
Response.Write(string.Format("<font color=red>{0}</font>={1}<br>", entry.Key, entry.Value));
}为什么结果是
d=2
c=3
1=a
a=1
,请大家主意输出的顺序
foreach (DictionaryEntry entry in ht)
{
Response.Write(string.Format("<font color=red>{0}</font>={1}<br>", entry.Key, entry.Value));
}为什么结果是
d=2
c=3
1=a
a=1
,请大家主意输出的顺序
a c d 1
foreach (KeyValuePair<string,string> entry in ht)
{
Response.Write(string.Format("<font color=red>{0}</font>={1}<br>", entry.Key, entry.Value));
}
参考
var ht = new Hashtable {{"1", "a"}, {"d", "2"}, {"a", "1"}, {"c", "3"}};
foreach (DictionaryEntry entry in ht)
{
Response.Write(string.Format("<font color=red>{0}</font>={1}-------{2}:{3}---{4}<br>",
entry.Key, entry.Value,entry.Key.GetHashCode(), entry.Value.GetHashCode(),entry.Key.GetHashCode()+entry.Value.GetHashCode()));
}
结果
d=2-------372029370:372029328---744058698
c=3-------372029375:372029327---744058702
1=a-------372029325:372029373---744058698
a=1-------372029373:372029325---744058698我把key和value都GetHashCode,还是看不出来是按照什么顺序啊.
我就是想了解一下hashtable呵呵
一般这种情况用Dictionary来做
生成的hash值我也列出来了啊,没见按照这个排序啊