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 );