zoukankan      html  css  js  c++  java
  • List Dictionary 排序

    1、List

    List<string> temp = new List<string>();
    foreach (PlayAgentItem arg in PlayAgentConfigSection.values.Cast<PlayAgentItem>())
    {
      temp.Add(arg.IpAddr);
    }
    temp = temp.OrderBy(u => u).ToList();

    2、Dictionary

     private Dictionary<IPAddress, Seat> SeatList;
     SeatList.OrderBy(r => r.Value.ID).ToDictionary(r => r.Key, r => r.Value)

    Seat类要实现IComparable的CompareTo接口
    public class Seat, IComparable<Seat>
    {
         /// <summary>
            ///
            /// </summary>
            /// <param name="obj"></param>
            /// <returns></returns>
            public int CompareTo(Seat obj)
            {
                if (this.ID == obj.ID)
                {
                    return 0;
                }
                else if (this.ID > obj.ID)
                {
                    return 1;
                }
                else
                {
                    return -1;
                }
            }
    }
  • 相关阅读:
    1036 商务旅行
    4165 ​高精度求阶乘
    3117 高精度练习之乘法
    封装代理
    freemarker写select组件(三)
    VC双缓冲画图技术介绍
    JS学习十七天----工厂方法模式
    Struts2 全局结果集
    HDU 1730 Northcott Game
    C++ STL:vector
  • 原文地址:https://www.cnblogs.com/ChangTan/p/12936768.html
Copyright © 2011-2022 走看看