5

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
2
  • what's the .NET framework version you are using? this code should work fine in .Net 4 and above Commented Dec 16, 2014 at 8:19
  • VS2012 target framework 4.0. Commented Dec 16, 2014 at 8:21

1 Answer 1

4

Sorting can be done using Linq via the following statement.

var Result = callResponse.Report.OrderBy( iItem => iItem.CompletedDate );
Sign up to request clarification or add additional context in comments.

4 Comments

This is the way I thought I would go but callResponse.Report has no OrderBy method.
Please show the definition of InvokeRepoerRequestListResponse.
@Fred have you using System.Linq?
@pwas Thank you! I cant believe I missed that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.