Sort简单排序
List<T> 类型排序:
public List<ProductionMaterialModel> OrderBybom(List<ProductionMaterialModel> bommodel, bool prace)
{
List<ProductionMaterialModel> bomlist = new List<ProductionMaterialModel>();
try
{
if (bommodel != null && bommodel.Count > 0)
{
var is_stringa = 0;
var is_stringb = 0;
bommodel.Sort((a, b) =>
{
string ia = Regex.Match(a.place_no, @"\d+$").Value;//正则匹配时否是整数开头
string ib = Regex.Match(b.place_no, @"\d+$").Value;
int.TryParse(a.place_no, out is_stringa);//验证字符串是否包含数字,0 false,1 true
int.TryParse(b.place_no, out is_stringb);
return (ia != "" && ib != "" && is_stringa != 0 && is_stringb != 0) ? int.Parse(a.place_no) - int.Parse(b.name) : string.Compare(a.name, b.name);//判断比较的两个string是否是空值或字符串如果不是则按数字排序,排序结果顺序为:字符—数字—字母—汉字
});
foreach (var item in bommodel)
{
if (!string.IsNullOrWhiteSpace(item.place_no))
{
bomlist.Add(item);//剔除为空的string
}
}
if (prace)
{
bomlist.Reverse();//将整个集合的元素反转
}
bomlist.AddRange(bommodel.Where(p => string.IsNullOrWhiteSpace(p.place_no)).ToList());//累加为空的string持续放到最后
}
}
catch (Exception ex)
{
throw;
}
return bomlist;
}
--供个人学习使用
Sort简单排序的更多相关文章
- List<T>集合的Sort自定义排序用法简单解析
List<T>集合的Sort自定义排序用法简单解析: 如下:一系列无序数字,如果想要他们倒序排列,则使用如下代码: 那么如何理解这段代码呢? (x,y)表示相邻的两个对象,如果满足条件:x ...
- 简单排序算法 C++类实现
简单排序算法: 冒泡排序 插入排序 选择排序 .h代码: // // SortClass.h // sort and selection // // Created by wasdns on 16/1 ...
- counting sort 计数排序
//counting sort 计数排序 //参考算法导论8.2节 #include<cstdio> #include<cstring> #include<algorit ...
- erlang下lists模块sort(排序)方法源码解析(二)
上接erlang下lists模块sort(排序)方法源码解析(一),到目前为止,list列表已经被分割成N个列表,而且每个列表的元素是有序的(从大到小) 下面我们重点来看看mergel和rmergel ...
- erlang下lists模块sort(排序)方法源码解析(一)
排序算法一直是各种语言最简单也是最复杂的算法,例如十大经典排序算法(动图演示)里面讲的那样 第一次看lists的sort方法的时候,蒙了,几百行的代码,我心想要这么复杂么(因为C语言的冒泡排序我记得不 ...
- Spring Data JPA使用Sort进行排序(Using Sort)(转)
通过上一节的学习,我们知道了如何用@Query注解来实现灵活的查询.在上一节的示例中,我也尝试给出简单的排序,通过JPQL语句以及原生SQL来实现的.这样的实现,虽然在一定程度上可以应用,但是灵活度不 ...
- 《Algorithms算法》笔记:元素排序(1)——简单排序
<Algorithms算法>元素排序(1)——简单排序 Algorithms算法元素排序1简单排序 排序问题 1 回调函数 2Java中回调函数的路线图 3 全序 4 Comparable ...
- 『ACM C++』HDU杭电OJ | 1425 - sort (排序函数的特殊应用)
今天真的是累哭了,周一课从早八点半一直上到晚九点半,整个人要虚脱的感觉,因为时间不太够鸭所以就回头看看找了一些比较有知识点的题来总结总结分析一下,明天有空了就开始继续打题,嘻嘻嘻. 今日兴趣电影: & ...
- golang slice 简单排序
原文链接:https://www.jianshu.com/p/603be4962a62 demo package main import ( "fmt" "sort&qu ...
随机推荐
- AngularJS 路由
AngularJS 路由允许我们通过不同的 URL 访问不同的内容. 通过 AngularJS 可以实现多视图的单页Web应用(single page web application,SPA). 通常 ...
- 【leetcode】Merge Sorted Array
题目描述 Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assu ...
- VS2015 编译 Qwt6.1.3
VS2015 + Qt5.7 编译 Qwt6.1.3 1. 将 qwtconfig.pri 中的 C:\Qwt 改为 D:/ProgramFiles/C_Library/Qwt/Qwt , 我的Qw ...
- MySQL深度巡检
1. IO层面检查 (1)IO检查 查看%util是否接近100%定位是哪个磁盘IO压力大 #iostat -x 1 10 (2)iotop定位负载来源进程 查看哪个PID占用IO最高 #io ...
- 数据分析(8):Series介绍
Series Series由一组数据及索引组成 索引 采用默认索引 data = pd.Series([4, 3, 2, 1]) 自定义索引 data = pd.Series([4, 3, 2, 1] ...
- Beginning Scala study note(3) Object Orientation in Scala
1. The three principles of OOP are encapsulation(封装性), inheritance(继承性) and polymorphism(多态性). examp ...
- D3中selection之使用
1. 极为重要的reference: [1] How selections works. http://bost.ocks.org/mike/selection/ [2] Nested selecti ...
- 用vue2 +vue-router2 + es6 +webpack 高仿饿了么app(干货满满)
#高仿饿了么app商家详情 (vue2 +vue-router2 + es6 +webpack ) ##demo [demo 地址](http://liangxiaojuan.github.io/ ...
- Linux学习笔记(11)-kill函数
明天开始学习kill函数的用法. ---------------------------------------------- kill函数可以用来向指定的进程发送一个指定的信号,在我的理解的来看,就 ...
- VS2012调试时很慢的解决方案
1.转自http://guooge.com/archives/408.html VS2010调试极慢获取出现死机,因为启动了IntelliTrace Visual Studio 2010 Ulti ...