Sort list by date

I tried the solutions I found and cannot make this work work for me.

I have a class:

public class InvokeGetReportRequestListResponse { public MarketplaceWebServiceException Error { get; set; } public bool CallStatus { get; set; } public List<RequestedReport> Reports { get; set; } } public class RequestedReport { public String ReportRequestId; public String ReportType; public DateTime? StartDate; public DateTime? EndDate; public Boolean Scheduled; public DateTime? SubmittedDate; public String ReportProcessingStatus; public String GeneratedReportId; public DateTime? StartedProcessingDate; public DateTime? CompletedDate; } 

I call the service:

 InvokeGetReportRequestListResponse callResponse = InvokeGetReportRequestList(callRequest); 

And now I want to sort the Reports list in callResponse to CompletedDate

callResponse.Reports.Sort((x, y) => DateTime.Compare(x.CompletedDate, y.CompletedDate));

This returns an error:

 Cannot convert lambda expression to type 'System.Collections.Generic.IComparer<WebFeeds.Amazon.API.DataTypes.RequestedReport>' because it is not a delegate type 
+5
source share
1 answer

Sorting can be done using Linq using the following statement.

 var Result = callResponse.Report.OrderBy( iItem => iItem.CompletedDate ); 
+4
source

Source: https://habr.com/ru/post/1209205/


All Articles