当前位置:   article > 正文

C# Dictionary根据Key排序_c#给dictionary按key排序

c#给dictionary按key排序

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace ConsoleApplication1
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<int, string> test = new Dictionary<int, string> { };
  12. test.Add(0,"000");
  13. test.Add(4, "444");
  14. test.Add(2, "222");
  15. test.Add(6, "666");
  16. Dictionary<int, string> dic1Asc = test.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);
  17. Console.WriteLine("小到大排序");
  18. foreach(KeyValuePair<int,s
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号