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

c#字典排序

时间:2017-11-27 23:43:37      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:esc   索引   class   derby   bsp   c#   个数   console   system   

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dic排序
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, int> dic = new Dictionary<string, int>();
            dic.Add("q", 3);
            dic.Add("d", 9);
            dic.Add("f", 5);
            dic.Add("g", 6);
            dic.Add("l", 1);
            dic.Add("h", 0);
            //ascending升序
            //descending降序
            var dicSort = from objDic in dic orderby objDic.Value ascending select objDic;


            //int num = dicSort.Count();集合的个数
            //int a = dicSort.ElementAt(0).Value;指定索引0的值
            //也可以用for循环
            foreach (KeyValuePair<string, int> kvp in dicSort)
            {
                Console.WriteLine(kvp.Key + "" + kvp.Value);
            }

            Console.ReadKey();
        }
    }

 

c#字典排序

标签:esc   索引   class   derby   bsp   c#   个数   console   system   

原文地址:http://www.cnblogs.com/sanyejun/p/7906303.html

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