How To Sort a List<T>?

This question already has an answer here: How to Sort a List<T> by a property in the object 19 answers Your example code will not compile, because the ID property of your class needs to be an int instead of a string and you need to put double quotes around your string values, like this: public class Checkit { public int ID { get; set; } public string b { get; set; } public

如何对列表进行排序<T>?

这个问题在这里已经有了答案: 如何按对象中的属性排序列表<T> 19答案 你的示例代码不会被编译,因为你的类的ID属性需要是一个int而不是一个string ,你需要在你的字符串值中加双引号,如下所示: public class Checkit { public int ID { get; set; } public string b { get; set; } public string c { get; set; } } List<Checkit> Lst_Ch = new List<Checkit>(); Lst_Ch.Add(new Checkit {

How do I order by lastname?

This question already has an answer here: How to Sort a List<T> by a property in the object 19 answers You can use OrderBy for that: @foreach (var LedenA in Model.Groepen.AllMembers.OrderBy(x => x.Anaam)) { } If you want to sort on the first name after that, use ThenBy : @foreach (var LedenA in Model.Groepen.AllMembers.OrderBy(x => x.Anaam).ThenBy(x => x.Vnaam)) { }

我如何按姓氏排序?

这个问题在这里已经有了答案: 如何按对象中的属性排序列表<T> 19答案 您可以使用OrderBy : @foreach (var LedenA in Model.Groepen.AllMembers.OrderBy(x => x.Anaam)) { } 如果您想在此之后排序第一个名称,请使用ThenBy : @foreach (var LedenA in Model.Groepen.AllMembers.OrderBy(x => x.Anaam).ThenBy(x => x.Vnaam)) { }

Order List<Object> by property name

This question already has an answer here: How to Sort a List<T> by a property in the object 19 answers you would need to calculate a key to sort by List<Test> ordered = values.OrderBy(v => v.Value.StartsWith(">") ? "ZZ" + v.Value : v.Value ).ToList(); "ZZ" is an arbitrary key that will sort the values starting with ">" after all English ter

按属性名称排序列表<对象>

这个问题在这里已经有了答案: 如何按对象中的属性排序列表<T> 19答案 你需要计算一个键来排序 List<Test> ordered = values.OrderBy(v => v.Value.StartsWith(">") ? "ZZ" + v.Value : v.Value ).ToList(); “ZZ”是一个任意的键,它将按照所有英文术语排序以“>”开头的值。 (作为字母表中的最后一个字母,并且没有以两个Z开始的英文单词)。 SInce“>”的字节值低于任何一个Z不够的字母

How can I sort a list of objects by a member of each object?

This question already has an answer here: How to Sort a List<T> by a property in the object 19 answers Pretty standard, simple linq. var candleList = candleList.Distinct().OrderBy(x => x.date).ToList(); As Adam mentioned below, this will only remove duplicate instances within the list, not instances which all of the same property values. You can implement your own IEqualityCompar

我如何通过每个对象的成员对对象列表进行排序?

这个问题在这里已经有了答案: 如何按对象中的属性排序列表<T> 19答案 漂亮的标准,简单的linq。 var candleList = candleList.Distinct().OrderBy(x => x.date).ToList(); 正如Adam在下面提到的,这只会删除列表中的重复实例,而不是具有所有相同属性值的实例。 您可以实现自己的IEqualityComparer<Candle>作为通过它的选项。 的IEqualityComparer 你可能想看看msdn,并阅读Linq和Enumerable方法:MS

Sort list of class objects in c#

This question already has an answer here: How to Sort a List<T> by a property in the object 19 answers Using LINQ: tocke = tocke.OrderBy(x=> x.t.X).ToList(); Make t public. Direct solution without LINQ (just list sorting, no additional list creation). Providing that t is made public: tocke.Sort((left, right) => left.t.X - right.t.X); But the best way, IMHO, is to make c

在c#中对类对象排序

这个问题在这里已经有了答案: 如何按对象中的属性排序列表<T> 19答案 使用LINQ: tocke = tocke.OrderBy(x=> x.t.X).ToList(); 让t公众。 没有LINQ的直接解决方案(只是列表排序,没有额外的列表创建)。 提供这个t是公开的: tocke.Sort((left, right) => left.t.X - right.t.X); 但是,恕我直言,最好的办法是让class tocka可比: class tocka: IComparable<tocka> { ... public int C

C# : Sort list on custom property

This question already has an answer here: How to Sort a List<T> by a property in the object 19 answers This might be inefficient, but you could add a DateTime property to your MyEvent class that converts StartDate to a DateTime and sort on that: public class MyEvent { public int EventId{get;set;} public MyDate StartDate{get;set;} public DateTime MyStartDate { get { return D

C#:自定义属性的排序列表

这个问题在这里已经有了答案: 如何按对象中的属性排序列表<T> 19答案 这可能效率低下,但是您可以将DateTime属性添加到MyEvent类中,该类将StartDate转换为DateTime并对其进行排序: public class MyEvent { public int EventId{get;set;} public MyDate StartDate{get;set;} public DateTime MyStartDate { get { return DateTime.Parse(StartDate.MMDDYYYYHHMMSS); } } } var sorted = myEvents.Order

How to sort a list by a specific property in .NET 2.0?

This question already has an answer here: How to Sort a List<T> by a property in the object 19 answers Check Sort method, that takes Comparison<T> . Avaliable from .NET 2.0 var list = new List<Point>{ /* populate list */ }; list.Sort(Comparison); public int Comparison (Point a, Point b) { //do logic comparison with a and b return -1; } 你需要使用一个委托,几乎是

如何按.NET 2.0中的特定属性对列表进行排序?

这个问题在这里已经有了答案: 如何按对象中的属性排序列表<T> 19答案 检查Sort方法,该方法需要Comparison<T> 。 从.NET 2.0可用 var list = new List<Point>{ /* populate list */ }; list.Sort(Comparison); public int Comparison (Point a, Point b) { //do logic comparison with a and b return -1; } 你需要使用一个委托,几乎是一个单一的:) list.Sort(delegate(Point p1, Point p2)

How to sort class list by integer property?

This question already has an answer here: How to Sort a List<T> by a property in the object 19 answers 尝试这个: List<Person> SortedList = people.OrderBy(o=>o.Age).ToList(); people.Sort((p1, p2) => { return p1.Age - p2.Age; });

如何通过整数属性对类列表进行排序?

这个问题在这里已经有了答案: 如何按对象中的属性排序列表<T> 19答案 尝试这个: List<Person> SortedList = people.OrderBy(o=>o.Age).ToList(); people.Sort((p1, p2) => { return p1.Age - p2.Age; });

How to sort List<Point>

This question already has an answer here: How to Sort a List<T> by a property in the object 19 answers LINQ: pointsOfList = pointsOfList.OrderByDescending(p => p.X).ToList(); pointsOfList.OrderBy(p=>p.x).ThenBy(p=>p.y) 这个简单的控制台程序可以: class Program { static void Main(string[] args) { List<Points> pointsOfList = new List<Points>(){

如何对List <Point>进行排序

这个问题在这里已经有了答案: 如何按对象中的属性排序列表<T> 19答案 LINQ: pointsOfList = pointsOfList.OrderByDescending(p => p.X).ToList(); pointsOfList.OrderBy(p=>p.x).ThenBy(p=>p.y) 这个简单的控制台程序可以: class Program { static void Main(string[] args) { List<Points> pointsOfList = new List<Points>(){ new Points() { x = 9, y = 3

How can I improve this function under CUDA?

Can I improve the following function under CUDA ? What the function does is, Given a min and max , ELM1 and ELM , check if any three numbers of array ans[6] are found in any row, from min to max , in array D1 , D2 , D3 , D4 , D5 , D6 , if found return 1. I tried using loops , OR -ing, AND -ing, replacing goto with flag etc. etc. But this seems to be the fastest way. __device__ bool THREEA

我如何在CUDA下改进此功能?

我可以在CUDA下改进以下功能吗? 该功能所做的是, 给定一个min和max , ELM1和ELM ,检查是否阵列的任何三个数字ans[6]中的任何行被找到,从min到max ,在阵列D1 , D2 , D3 , D4 , D5 , D6 ,若发现返回1 。 我尝试使用loops , OR -ing, AND -ing,用标志等替换goto等。但这似乎是最快的方法。 __device__ bool THREEA(unsigned int n0, unsigned int n,unsigned int* ST1,unsigned int* D1, unsigned int* D2,un