tnfh.net
当前位置:首页 >> C# list 排序 >>

C# list 排序

//eg:public class Root{ public string Name{set;get;} public int Sort{set;get;} public ........ .....}public class MyClass{ List list = ....数据源 public void SortFunction() { var result = list.OrderBy(x=>x.Sort); //按照sort属性...

System.Collections.Generic.List ints = new List(); ints.Sort();// 排序 ints.Reverse();// 反转顺序

List list=new List(new DirectoryInfo("路径").GetFiles()); list.Sort(); 这样行不? 那就用函数来实现排序吧 private void Form1_Load(object sender, EventArgs e) { List list = new List(new DirectoryInfo(@"路径").GetFiles()); Compari...

一共给出了3种实现方式,运行前需要自己将其他的方法注释掉。 using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ListSort{ class Program { static void Main(string[] args) { List L = new List...

首先要知道往List里面添加数据的对象类型,假设为Project类型这样写Project myproject = 你要判断的数据;bool listHasMyproject = false;foreach(var item in list.Items){Project proj = (Project)item;if(proj.equals(myProject))//判断是不是...

第一种:实体类实现IComparable接口,而且必须实现CompareTo方法 class Info:IComparable { public int Id { get; set; } public string Name { get; set; } public int CompareTo(object obj) { int result; try { Info info = obj as Info; if...

你可以试试OrderBy()方法或者OrderByDescending()方法: List list=....;list=list.OrderBy(x>x.ID).ToList();

升序排列 List tmp = new List(){5,1,22,11,4}; tmp.Sort((x, y) => x.CompareTo(y)); Console.WriteLine(tmp); 降序排列 List tmp = new List(){5,1,22,11,4}; tmp.Sort((x, y) => -x.CompareTo(y));//这里写-x就是降序了 Console.WriteLine(tmp);

var sorted=listUsers.OrderBy(x=>x.Age); foreach(user u in sorted) //这里已经是排序过的了

象下面这样 public class student { public string name; public int age; } void SortStudents() { var students = new List(); students.Sort((student1, student2) => student1.age - student2.age); }

网站首页 | 网站地图
All rights reserved Powered by www.tnfh.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com