有没有像Dictionary<string, List<string>>顺序存储的结构

来源:百度知道 编辑:UC知道 时间:2024/06/15 06:24:18
foreach的时候, dictionary是乱序的, 什么结构是顺序,或是排序的

没有,要自己手动排序一次

using System.Linq;

Dictionary<string, List<string>> s = new Dictionary<string, List<string>>();
s.Add("009", new List<string> { "009" });
s.Add("001", new List<string> { "001" });
var v =s.OrderBy(d => d.Key);
foreach (var item in v) { Console.WriteLine(item.Key);}