今天用 Hashtable 时发现结果的顺序并非为元素 Add 的顺序. 后改用ListDictionary 得以解决.
请见如下 code
using System.Collections;
static Hashtable _period;
static frmMain()
{
_period = new Hashtable();
_period.Add("Month", 12);
_period.Add("Quarter", 4);
_period.Add("Half Year", 2);
_period.Add("Full Year", 1);
ICollection period_type = _period.Keys;
foreach (string s in period_type)
{
Console.WriteLine(s);
}
}
output
--------
Month
Half Year
Full Year
Quarter
using System.Collections.Specialized;
static ListDictionary _period;
static frmMain()
{
_period = new ListDictionary();
_period.Add("Month", 12);
_period.Add("Quarter", 4);
_period.Add("Half Year", 2);
_period.Add("Full Year", 1);
ICollection period_type = _period.Keys;
foreach (string s in period_type)
{
Console.WriteLine(s);
}
}
output
--------
Month
Quarter
Half Year
Full Year