예제 #1
0
    // ReSharper disable once RedundantNameQualifier
    private List <KeyValuePair <string, float> > SortBarData(System.Collections.Generic.Dictionary <string, float> bar)
    {
        var comparer = new ATPComparer();

        var result = bar.OrderBy(
            i => i.Key, comparer)
                     .ToList();

        return(result);
    }
예제 #2
0
 /// <summary>
 /// 将集合内非空参数值的参数按照参数名ASCII码从小到大排序(字典序),使用URL键值对的格式(即key1=value1&amp;key2=value2…)拼接成字符串stringA
 /// </summary>
 /// <param name="dictionarys">参数(键值对)字典</param>
 /// <param name="isAsc">参数(键值对)字典的主键排序</param>
 /// <returns></returns>
 public static System.Collections.Generic.Dictionary <string, string> Sort(this System.Collections.Generic.Dictionary <string, string> dictionarys, bool isAsc = true)
 {
     System.Collections.Generic.Dictionary <string, string> newDictionarys = new System.Collections.Generic.Dictionary <string, string>();
     foreach (System.Collections.Generic.KeyValuePair <string, string> item in dictionarys)
     {
         if (!string.IsNullOrWhiteSpace(item.Key) && !string.IsNullOrWhiteSpace(item.Value))
         {
             newDictionarys.Add(item.Key, item.Value);
         }
     }
     if (isAsc)
     {
         return(newDictionarys.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value));                //将集合内非空参数值的参数按照参数名ASCII码从小到大排序(字典序)
     }
     else
     {
         return(newDictionarys.OrderByDescending(o => o.Key).ToDictionary(o => o.Key, p => p.Value));                //将集合内非空参数值的参数按照参数名ASCII码从大到小排序(字典降序)
     }
 }