码迷,mamicode.com
首页 > 编程语言 > 详细

Dictionary<string, string> 排序

时间:2014-11-11 10:34:11      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:style   io   color   ar   os   sp   for   on   cti   

.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

Dictionary<string, string> 排序

标签:style   io   color   ar   os   sp   for   on   cti   

原文地址:http://www.cnblogs.com/flywing/p/4088768.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!