Dictionary<string, string> 排序_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > Dictionary<string, string> 排序

Dictionary<string, string> 排序

 2014/11/11 10:56:27  随心随记  程序员俱乐部  我要评论(0)
  • 摘要:.netframework2.0版Dictionary<string,string>collection=newDictionary<string,string>();collection.Add("key3","value3");collection.Add("key1","value1");collection.Add("key4","value4");collection.Add("key2","value2");List<KeyValuePair<
  • 标签:

.net framework 2.0 版

Dictionary<string, string> collection = new Dictionary<string, string> ();

collection.Add("key3","value3");

collection.Add("key1","value1");

collection.Add("key4","value4");

collection.Add("key2","value2");

List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>(collection);

list.Sort(delegate(KeyValuePair<string, string> pair1, KeyValuePair<string, string> pair2)
{
  return pair1.Key.CompareTo(pair2.Key);
});

StringBuilder sb = new StringBuilder();

foreach (KeyValuePair<string, string> pair in list)
{
  sb.Append(pair.Key);
  sb.Append("=");
  sb.Append(pair.Value);
  sb.Append("&");
}

string str = sb.ToString().TrimEnd('&');

//str 值key1=value1&key2=value2&key3=value3&key4=value4

  • 相关文章
发表评论
用户名: 匿名