I use spring.net inject a Dictionary<string,string>
in this order:
<object id="dictLang" type="System.Collections.Generic.Dictionary<string,string>">
<constructor-arg>
<dictionary key-type="string" value-type="string" merge="0">
<entry key="zh-CN" value="中文" />
<entry key="en-US" value="英文" />
<entry key="th-TH" value="泰文" />
</dictionary>
</constructor-arg>
</object>
When I use foreach to iterate it, it outputs this:
code=en-US,name=英文
code=th-TH,name=泰文
code=zh-CN,name=中文
I found it is ordered by the key, how can I keep the order as I injected it?
When I create a dictionary manually:
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("zh-CN", "中文");
dic.Add("en-US", "英文");
dic.Add("th-TH", "泰文");
It is the same order when I iterate it, that's weird!
I thought about using OrderedDictionary
, but I don't know how to inject.