Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按日期时间排序列表_C# - Fatal编程技术网

C# 按日期时间排序列表

C# 按日期时间排序列表,c#,C#,我已经尝试了我找到的解决方案,但似乎无法让这一切对我起作用 我有一门课: public class InvokeGetReportRequestListResponse { public MarketplaceWebServiceException Error { get; set; } public bool CallStatus { get; set; } public List<RequestedReport> Reports { get; set; }

我已经尝试了我找到的解决方案,但似乎无法让这一切对我起作用

我有一门课:

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;
}
现在我想按
CompletedDate
callResponse
中的
Reports
列表进行排序

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

这将返回一个错误:

Cannot convert lambda expression to type 'System.Collections.Generic.IComparer<WebFeeds.Amazon.API.DataTypes.RequestedReport>' because it is not a delegate type
无法将lambda表达式转换为类型“System.Collections.Generic.IComparer”,因为它不是委托类型

可以通过以下语句使用Linq进行排序

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

这是我本以为会采用的方法,但是
callResponse.Report
没有
OrderBy
方法。请显示
InvokeRepoerRequestListResponse
@Fred您是否使用了
系统。Linq
?@pwas谢谢!我真不敢相信我错过了。您使用的.NET framework版本是什么?此代码在.NET4及以上版本VS2012目标框架4.0中应该可以正常工作。
var Result = callResponse.Report.OrderBy( iItem => iItem.CompletedDate );