zoukankan      html  css  js  c++  java
  • Dictionary<string, string> 排序

    .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
  • 相关阅读:
    Maven项目类型和JAVASE项目和JAVAEE项目的关系
    使用faker 生成测试数据
    python 面向对象
    python csv读写
    分治
    django 部署
    js 时间格式转换
    python环境
    枚举
    递归
  • 原文地址:https://www.cnblogs.com/flywing/p/4088768.html
Copyright © 2011-2022 走看看