将14条记录从一个列表拉到另一个列表
本文关键字:列表 一个 另一个 记录 14条 | 更新日期: 2024-10-18 17:07:33
我在下面创建了以下列表。rsiCalcList已经填充了我想要的内容,但我需要将第一个15从rsiCalcList跳过第一个项目拉到firstRSICalculationHistInfo。我还附上了一个错误的尝试。我还附上了下面的错误。关于如何实现目标的一些指导
private class rsiCalcList
{
public string rsiCalcSymbol { get; set; }
public DateTime rsiCalcDate { get; set; }
public decimal rsiCalcCloseChange { get; set; }
}
private class firstRSICalculationHistInfo
{
public string firstRSISymbol { get; set; }
public DateTime firstRSICalcDate { get; set; }
public decimal firstRSICloseChange { get; set; }
}
irstRSIHistInfo = rsiCalcList
.Select(x => new firstRSICalculationHistInfo { firstRSISymbol = x.rsiCalcSymbol, firstRSICalcDate = x.rsiCalcDate, firstRSICloseChange = x.rsiCalcCloseChange })
.OrderBy(x => x.firstRSICloseChange)
.Skip(1)
.Take(15);
错误
Error CS0266 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<AfterTrade.RelativeStrengthIndex.firstRSICalculationHistInfo>' to 'System.Collections.Generic.List<AfterTrade.RelativeStrengthIndex.firstRSICalculationHistInfo>'. An explicit conversion exists (are you missing a cast?) AfterTrade C:'Users''Documents'Projects'Stockton'Development'AfterTrade'RelativeStrengthIndex.cs 86 Active
使用.ToList()
解决您的查询。
irstRSIHistInfo = rsiCalcList
.Select(x => new firstRSICalculationHistInfo { firstRSISymbol = x.rsiCalcSymbol, firstRSICalcDate = x.rsiCalcDate, firstRSICloseChange = x.rsiCalcCloseChange })
.OrderBy(x => x.firstRSICloseChange)
.Skip(1)
.Take(15)
.ToList();
据我所见,您的Linq是有效的。但是,.Take()返回一个IEnumerable。似乎irstRSIHistInfo
是List类型。因此,将.ToList()添加到Linq语句的末尾。