Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting List by DateTime

Tags:

c#

I have tried the solutions I have found and cannot seem to make this 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 make a call to a service:

InvokeGetReportRequestListResponse callResponse = InvokeGetReportRequestList(callRequest);

And now I want to sort the Reports list in callResponse by 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
like image 454
Fred Avatar asked Sep 30 '22 05:09

Fred


1 Answers

Sorting can be done using Linq via the following statement.

var Result = callResponse.Report.OrderBy( iItem => iItem.CompletedDate );
like image 157
Codor Avatar answered Oct 03 '22 07:10

Codor