这里是针对.NET版本过低的排序方式,没怎么用过,记录一下;

一、创建字典Dictionary 对象

  假如 Dictionary 中保存的是一个网站页面流量,key 是网页名称,值value对应的是网页被访问的次数,由于网页的访问次要不断的统计,所以不能用 int 作为 key,只能用网页名称,创建 Dictionary 对象及添加数据代码如下:

Dictionary<string, int> dic = new Dictionary<string, int>();
  dic.Add("index.html", );
  dic.Add("product.html", );
  dic.Add("aboutus.html", );
  dic.Add("online.aspx", );
  dic.Add("news.aspx", );

二、.net 2.0 版本 Dictionary排序

List<KeyValuePair<string, int>> lst = new List<KeyValuePair<string, int>>(dic);

  //倒叙排列:只需要把变量s2 和 s1 互换就行了 例: return s1.Value.CompareTo(s2.Value);
  //进行排序 目前是顺序

      lst.Sort(delegate(KeyValuePair<string, int> s1, KeyValuePair<string, int> s2)
      {
        return s2.Value.CompareTo(s1.Value);
      });
      dic.Clear();

 三、.net 3.5 以上版本 Dictionary排序(即 linq dictionary 排序)

  使用linq排序

var dicSort = from objDic in dic orderby objDic.Value descending select objDic;
输出要用这个输出:
foreach(KeyValuePair<string, int> kvp in dicSort)
{
  Response.Write(kvp.Key + ":" + kvp.Value + "<br />");
}

C#字典Dictionary排序(顺序、倒序)的更多相关文章

  1. java List排序 顺序 倒序 随机

    List list = new LinkedList(); for ( int i = 0 ; i < 9 ; i ++ ) { list.add( " a " + i); ...

  2. c# 关于字典dictionary 按时间排序

    上文中说到sortedlist 排序是键排序,不符合项目要求问题,接着使用字典dictionary 对value 为时间按照升序排序,问题解决.中间涉及到linq的使用.还有其他的写法,但发现下边的写 ...

  3. C#文件和文件文件夹按时间、名称排序-顺序与倒序

    对于文件和文件夹有多种排序方式,常用的就是按创建或修改时间.按文件名排序.在 C# 中,按时间和文件名排序都十分简单,用数组提供的排序方法 Array.Sort() 一行代码就可以搞定,当然也可以用常 ...

  4. C#创建安全的字典(Dictionary)存储结构

    在上面介绍过栈(Stack)的存储结构,接下来介绍另一种存储结构字典(Dictionary). 字典(Dictionary)里面的每一个元素都是一个键值对(由二个元素组成:键和值) 键必须是唯一的,而 ...

  5. C#语法基础用法Dictionary排序

    Dictionary排序 1.先看效果图: 2.核心逻辑如下: Dictionary<int, string> list = new Dictionary<int, string&g ...

  6. !!Python字典增删操作技巧简述+Python字典嵌套字典与排序

    http://developer.51cto.com/art/201003/186006.htm Python编程语言是一款比较容易学习的计算机通用型语言.对于初学者来说,首先需要掌握的就是其中的一些 ...

  7. 你真的了解字典(Dictionary)吗? C# Memory Cache 踩坑记录 .net 泛型 结构化CSS设计思维 WinForm POST上传与后台接收 高效实用的.NET开源项目 .net 笔试面试总结(3) .net 笔试面试总结(2) 依赖注入 C# RSA 加密 C#与Java AES 加密解密

    你真的了解字典(Dictionary)吗?   从一道亲身经历的面试题说起 半年前,我参加我现在所在公司的面试,面试官给了一道题,说有一个Y形的链表,知道起始节点,找出交叉节点.为了便于描述,我把上面 ...

  8. python(46):对字典进行排序,多键值排序

    注:改于2017-12-07,python3 下 Removed dict.iteritems(), dict.iterkeys(), and dict.itervalues(). Instead: ...

  9. Python字典按值排序、包含字典的列表按字典值排序的方法

    operator.itemgetter函数 operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),要注意,operator.i ...

随机推荐

  1. Best Time to Buy and Sell Stock 解答

    Question Say you have an array for which the ith element is the price of a given stock on day i. If ...

  2. python局域网alive ip侦听

    python局域网alive ip侦听 作者:vpoet mails:vpoet_sir@163.com 注:写着玩,欢迎copy # -*- coding: cp936 -*- # coding = ...

  3. ssl相关

    http://www.willrey.com/support/ssl_DES.html http://www.07net01.com/linux/Linuxdejiamirenzhenggongnen ...

  4. apache 开启压缩功能

    apache如何开启压缩功能. 1,首先先确认是安装deflatte模块.如果未安装,可以重新编译apache添加参数--enable-deflate=shared ,或者扩展安装deflate模块, ...

  5. ref 关键字out关键字

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  6. 表空间使用情况统计[z]

    SELECT UPPER(F.TABLESPACE_NAME) "表空间名", D.TOT_GROOTTE_MB "表空间大小(M)", D.TOT_GROOT ...

  7. iOS FMDB

    FMDB FMDB概述 什么是FMDB * FMDB是iOS平台的SQLite数据库框架 * FMDB以OC的方式封装了SQLite的C语言API FMDB的优点 * 使用起来更加面向对象,省去了很多 ...

  8. MySQL server has gone away报错

    1.最近做插入数据库,然后一直报一个错.mysql server has gone away.(如下图) 查了好多资料,终于解决了.. 1.可能是连接超时..进入php.ini,修改wait_time ...

  9. 常用工具类,文件和内存的大小获取,shell脚本的执行

    /* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Versi ...

  10. express框架目录结构

    . ├── app.js ├── bin │   └── www ├── node_modules │   ├── body-parser │   ├── cookie-parser │   ├── ...