我在下面创建了以下列表。 rsiCalcList已经填充了我想要的东西,但我需要将第一个项目从rsiCalcList中拉出第一个到第一个RSICalculationHistInfo。我还附上了我的错误提示。我还附上了下面的错误。关于如何实现目标的一些指导
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
答案 0 :(得分:4)
使用.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();
答案 1 :(得分:1)
从我所看到的,你的Linq是有效的。但是,。Take()返回一个IEnumerable。 irstRSIHistInfo
似乎是List类型。因此,将.ToList()添加到Linq语句的末尾。