I have a general list ...
public List <ApprovalEventDto> ApprovalEvents
The EventDto statement has
public class ApprovalEventDto { public string Event { get; set; } public DateTime EventDate { get; set; } }
How to sort the list by event date?
You can use List.Sort () as follows:
ApprovalEvents.Sort((lhs, rhs) => (lhs.EventDate.CompareTo(rhs.EventDate)));
using System.Linq; void List<ApprovalEventDto> sort(List<ApprovalEventDto> list) { return list.OrderBy(x => x.EventDate).ToList(); }
ApprovalEvents.Sort((x, y) => { return x.EventDate.CompareTo(y.EventDate); });
, .NET 3.5, OrderBy, marxidad. , List.Sort.
List.Sort , IComparer - , , .
MiscUtil ProjectionComparer, ( OrderBy), CompareTo . , , , . ( MiscUtil. . .)
Darksiders, :
ApprovalEvents.Sort((a, b) => (a.EventDate.CompareTo(b.EventDate)));
. . WikiPedia, n-Log n-, .
For certain types of data, you can also use a pigeon to get order n due to more memory usage.
You can use the List.Sort () method with an anonymous method or a lambda expression. More on MSDN
Source: https://habr.com/ru/post/1697965/More articles:Saving configuration items in .net - c #What type of project is Entity Framework currently suitable for? - entity-frameworkWhat is the best way to find out the installed version of iPhone SDK? - iosAsp.Net MVC: Is there support for controller-level filter attributes? - c #Any view implementation for a JSP-Servlet application? - jspGet my WAN IP Address - web-servicesSee Javascript File in JQuery - jquerySQL Server 2005 - Эффект Rowsize для производительности запросов? - performanceWhere to start with HDL? - embeddedRegular Expression Algorithm - regexAll Articles