zoukankan      html  css  js  c++  java
  • C# List.Sort() 排序; DataView 对DataTable 排序

        List<string> sortedHeight = new List<string>();
                foreach (var cs in contourDoc.SelectNodes("Xml/ContourSet"))
                {
                    XmlElement tempEle = cs as XmlElement;
                    sortedHeight.Add(tempEle.Attributes["height"].Value);
                }
                sortedHeight.Sort(HeightComapare);

    Sort的参数类型是返回值为int的方法

            private static int HeightComapare(string x, string y)
            {
                return (int.Parse(x) - int.Parse(y));
            }

    传入值:"0" "180" "30" "90"

    返回值:"0" "30" "90" "180"

    ---------------------------------

    二、DataView 对DataTable 排序

      //按BuildingName 长度 排序
                dt.Columns.Add("NameLength");
                for (int i = 0; i <= dt.Rows.Count - 1; i++) {
                    dt.Rows[i]["NameLength"] = dt.Rows[i]["BuildingName"].ToString().Length;
                }
                DataView tempDv = dt.DefaultView;
                tempDv.Sort = "NameLength asc";//变更DataView的顺序
                dt=tempDv.ToTable();//从DV生成dataTable
    
  • 相关阅读:
    DC综合流程
    DC set_tcl脚本配置
    同步FIFO设计
    顺序脉冲 发生器
    状态机的写法
    verilog串并转换
    indexOf()
    jQuery 效果
    jQuery 事件
    jQuery css
  • 原文地址:https://www.cnblogs.com/imihiroblog/p/2590562.html
Copyright © 2011-2022 走看看