C# List<object> 按特定字段排序
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ListObjectSort
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- List<Student> list = new List<Student>();
- Student stu1 = new Student()
- {
- Number = ,
- Name = "石敏媛"
- };
- list.Add(stu1);
- Student stu2 = new Student()
- {
- Number = ,
- Name = "梁秀秀"
- };
- list.Add(stu2);
- Student stu3 = new Student()
- {
- Number = ,
- Name = "苏敏敏"
- };
- list.Add(stu3);
- Student stu4 = new Student()
- {
- Number = ,
- Name = "褚丽丽"
- };
- list.Add(stu4);
- DisplayInfomation(list);
- Comparison<Student> compari = new Comparison<Student>(Compart);
- list.Sort(compari);
- DisplayInfomation(list);
- }
- public static void DisplayInfomation(List<Student> list)
- {
- Console.WriteLine("--------------------------");
- foreach (Student stu in list)
- {
- Console.WriteLine(stu.Number + "\t\t" + stu.Name);
- }
- Console.WriteLine("--------------------------");
- }
- public static int Compart(Student stu1, Student stu2)
- {
- int result = ;
- CaseInsensitiveComparer objCompare = new CaseInsensitiveComparer();
- result = objCompare.Compare(stu1.Number, stu2.Number);
- return result;
- }
- }
- public class Student
- {
- public int Number { get; set; }
- public string Name { get; set; }
- }
- }
C# List<object> 按特定字段排序的更多相关文章
- 对文本行按特定字段排序(前N个字符或后N个字符),TCPL 练习5-17
The C programming language 的关于文本行排序的问题有很多种要求的方式,在对每行的字段排序方面,最简单的是例如对前N个字符或者末位N个字符进行排序,更高一点的要求是,对特殊符号 ...
- C#中List按特定字段排序
有一个类,如Student,有学号.数学成绩.语文成绩, 存在List列表中,要将List按数学成绩排序,怎么办呢? List<Student> scores=GetScores(); s ...
- SQL 按特定字段值排序
SQL 按特定字段值排序的代码,有需要的朋友可以参考下. id, name shandong01 name1 shandong02 name2 shandong03 name3 beijing01 n ...
- Java 多字段排序Comparator(兼容Date,Integer,Doubel,Long)
Java 反射类:ReflexUtil public class ReflexUtil { static Logger logger = LoggerFactory.getLogger(ReflexU ...
- EFCore+Mysql仓储层建设(分页、多字段排序、部分字段更新)
前沿 园子里已有挺多博文介绍了EFCore+Mysql/MSSql如何进行使用,但实际开发不会把EF层放在Web层混合起来,需要多个项目配合结构清晰的进行分层工作,本文根据个人实践经验总结将各个项目进 ...
- java实现按对象某个字段排序,排序字段和规则自定义
@SuppressWarnings({ "unchecked", "rawtypes" }) private <T> void sort(List& ...
- List<model>需要根据特定字段求差集的实现
list对象不能直接使用Except等封装好的函数,因为内存地址不一样(还有一些数虽然主数据一致但是update/create信息也不一致,对,我碰到的需求就是这么难受 TOT) 这时候我们的需求很多 ...
- Elasticsearch 6.2.3版本 string 类型字段 排序 报错 Fielddata is disabled on text fields by default
背景说明 最近在做一个 Elasticsearch 的分页查询,并且对查询结果按照特定字段进行排序的功能. 但是执行结果却报错,报错信息如下: { "error": { " ...
- 在Java中使用Collections.sort 依据多个字段排序
一.如何使用Collections工具类进行排序 使用Collections工具类进行排序主要有两种方式: 1.对象实现Comparable接口,重写compareTo方法 /** * @author ...
随机推荐
- [bzoj]2705: [SDOI2012]Longge的问题[数论][数学][欧拉函数][gcd]
[bzoj]P2705 OR [luogu]P2303 Longge的问题 Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需 ...
- BP算法演示
本文转载自https://mattmazur.com/2015/03/17/a-step-by-step-backpropagation-example/ Background Backpropaga ...
- RedisTemplate访问Redis数据结构(一)——String
当对String数据结构进行操作时,推荐直接使用spring-data-redis提供的StringRedisTemplate,其配置如下 <bean id="stringRedisT ...
- Oracle In子句
Oracle In子句 作者:初生不惑 Oracle基础 评论:0 条 Oracle技术QQ群:175248146 在本教程中,您将学习如何使用Oracle IN运算符来确定值是否与列表或子查询中的任 ...
- es之java分页操作
按照一般的查询流程来说,如果我想查询前10条数据: · 1 客户端请求发给某个节点 · 2 节点转发给个个分片,查询每个分片上的前10条 · 3 结果返回给节点,整合数据,提取前10条 · 4 返回给 ...
- LR之流程
一.新建事务 如何估算一个业务流程呢?一个业务流程的持续时间:登录,预定机票等等的花费时间,通常是几个步骤构成的,所以在LR中需要标记事物,作为评测业务的时间. 1.打开Basic_Tutorial脚 ...
- 论文keywords和规则匹配的baseline
详细的思路可以参照小论文树立0317 关键词分为以下几类: t/****一些通用的过滤词,这些通用的过滤词可以使用和节目一起出现的词语,结合tf-idf看出来么?*****/ public st ...
- fedora禁用(开机启动)服务和进程管理
首先要查看有哪些(开机启动)服务 chkconfig --list 或者: systemctl list-units 然后, 根据需要进行禁用服务的开机启动: chkconfig service_na ...
- Maven install报错:MojoFailureException ,To see the full stack trace of the errors, re-run Maven with the -e switch.解决
报错日志: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".SLF4J: Defaulting to ...
- VMware 虚拟化编程(9) — VMware 虚拟机的快照
目录 目录 前文列表 VMware 虚拟机的快照 快照的执行过程 删除快照 快照类型 Quiseced Snapshot 前文列表 VMware 虚拟化编程(1) - VMDK/VDDK/VixDis ...