读书人

为啥结果会是从后面的那个读起不是从

发布时间: 2012-10-14 14:55:07 作者: rapoo

为什么结果会是从后面的那个读起,不是从第一个开始读起?
/// <summary>
/// 使用hashtable显示键值对
/// </summary>
public static void UseNonGenericHashtable()
{
Hashtable numbers = new Hashtable();
numbers.Add(1, "one");
numbers.Add(2, "two");

foreach (DictionaryEntry de in numbers)
{
Console.WriteLine("Key:" + de.Key + "\tvalue:" + de.Value);
}
numbers.Clear();
}
运行结果为 Key:2 value:two
Key:1 value:one

[解决办法]
Hashtable ,这种的存储键值对的,就是没有顺序
[解决办法]

C# code
 Dictionary<int, string> dic = new Dictionary<int, string>();            dic.Add(1, "one");            dic.Add(2, "two");            foreach (var de in dic)            {                Console.WriteLine("Key:" + de.Key + "\tvalue:" + de.Value);            }            dic.Clear();
[解决办法]
键值对 我还是喜欢用 dictionary

探讨
C# code

Dictionary<int, string> dic = new Dictionary<int, string>();
dic.Add(1, "one");
dic.Add(2, "two");
foreach (var de in dic)
{
……

[解决办法]
哈希表就是散列表,没有一定的读取顺序的

读书人网 >asp.net

热点推荐