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;
                }
            }
    }
  • 相关阅读:
    Django 【第十二篇】Form组件进阶
    Django 【第十一篇】Form组件基础
    前端知识点总结
    vue组件续和前端工程化
    vue组件
    Vue视图下
    Vue实例与渲染
    BootStrap
    jQuery事件与动画
    dom操作 属性操作 样式操作
  • 原文地址:https://www.cnblogs.com/ChangTan/p/12936768.html
Copyright © 2011-2022 走看看