I intended to save properties of an object to a Hashtable. In this case, keys and values are not fixed types and I cannot use SortedList.
I have no idea what order the .NET framework add items to Hashtable when Add(key, value) method is applied. Monitoring the position items are added, I cannot find if key is the standard or value.
I thought basically Hashtable function acts randomly, therefore the order will be changed unexpectedly.
However :
foreach (object o in objs)
{
CheckSomething(o, ref e81_o, ref l83_hn, ref l83_o, ref score);
Hashtable fields = o.Fields;
fields.Add("E81_O", e81_o);
fields.Add("L83_HN", l83_hn);
fields.Add("L83_O", l83_o);
fields.Add("Score", score);
}
In the case above, iteratively fields in all objs have the same order! For example, o.Fields has items originally in the order like,
H
V
S
E
and all objs have fields in the same order like below,
Score
L83_O
H
L83_HN
V
E81_O
S
E
But, extracting items in the reverse order like Stack.
Hashtable fields = new Hashtable();
foreach (object o in fields.Keys)
{
sb.Append(o.ToString() + " / " + fields[o].ToString());
}