[已解决问题]
解决于 2008-08-04 11:14
<P>Hashtable和Dictionary<T,K>的内部排序算法不一样,请看代码</P><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<DIV class=cnblogs_code><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000"> Dictionary</SPAN><SPAN style="COLOR: #000000"><</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">></SPAN><SPAN style="COLOR: #000000"> ht</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Dictionary</SPAN><SPAN style="COLOR: #000000"><</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">></SPAN><SPAN style="COLOR: #000000">();<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://www.sina.com.cn</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://www.bjut.edu.cn</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://lib.bjut.edu.cn</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://news.bjut.edu.cn</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://sse.bjut.edu.cn</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://lexus.cnblogs.com</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://www.sina.com.cn/sport</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://www.sina.com.cn/ent</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff">foreach</SPAN><SPAN style="COLOR: #000000">(var kvp </SPAN><SPAN style="COLOR: #0000ff">in</SPAN><SPAN style="COLOR: #000000"> ht)<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> Console.WriteLine(kvp.Key);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> Console.WriteLine(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">============================================</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> Hashtable ht2</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Hashtable();<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht2.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://www.sina.com.cn</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht2.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://www.bjut.edu.cn</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht2.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://lib.bjut.edu.cn</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht2.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://news.bjut.edu.cn</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht2.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://sse.bjut.edu.cn</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht2.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://lexus.cnblogs.com</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht2.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://www.sina.com.cn/sport</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> ht2.Add(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">http://www.sina.com.cn/ent</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff">foreach</SPAN><SPAN style="COLOR: #000000">(DictionaryEntry i </SPAN><SPAN style="COLOR: #0000ff">in</SPAN><SPAN style="COLOR: #000000"> ht2)<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top> Console.WriteLine(i.Key);</SPAN></DIV>
<DIV class=cnblogs_code><SPAN style="COLOR: #000000">两组实现的代码一样,但是输出的排序结果不一样,这是为什么,我觉得Hashtable的排序应该是比较正常的,大家觉得呢?</SPAN></DIV>