分配函数的返回IEnumerable< MovingAverage>价值到另一个对象 [英] Assign a function's returned IEnumerable<MovingAverage> value to another object

查看:68
本文介绍了分配函数的返回IEnumerable< MovingAverage>价值到另一个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用这个函数:

    私人   静态    IEnumerable  <   MovingAverage  >     SimpleMovingAverage    
IEnumerable < IexTradingStock > 队列 int 句号

省略代码

{ 返回 movingAverages ;



这是调用MovingAverage的函数:

     MovingAverage   SMA   =        MovingAverage  ();   
SMA
= SimpleMovingAverage stocks < span class ="pln"style ="margin:0px; padding:0px; border:0px; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; font-family:inherit ; vertical-align:baseline; color:#303336"> period );



我在这一行收到错误"SMA = SimpleMovingAverage(stocks,period);"错误是"无法隐式转换类型'System.Collections.Generic.IEnumerable'到' myBackEnd.Models.MovingAverage'存在显式转换(你错过
a cast)


解决方案

< blockquote>

你正在返回它看起来的多个对象,所以你应该有 IEnumerable< MovigngAverage> 
来保存对该对象的引用。试试如下:

 IEnumerable< MovingAverage> SMA = SimpleMovingAverage(股票,期间); 


如果要返回单个对象,则需要更改方法的返回类型:

 private static MovingAverage SimpleMovingAverage(
IEnumerable< IexTradingStock> queue,int period)
{
// code here

return movignAeverage;
}

现在你应该可以这样做:

 MovingAverage = SimpleMovingAverage(股票,期间); 



希望有所帮助!


I am calling this function:

        private static IEnumerable<MovingAverage> SimpleMovingAverage(
        IEnumerable<IexTradingStock> queue, int period)
        .
        . (omitted code) 
        .
    {   return movingAverages;

This is the function that calls MovingAverage:

                MovingAverage SMA = new MovingAverage();
            SMA = SimpleMovingAverage(stocks, period);

I get an error on this line "SMA = SimpleMovingAverage(stocks, period);" The error is "Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'myBackEnd.Models.MovingAverage' an explicit conversions exists (are you missing a cast)

解决方案

You are returning multiple objects it seems like, so you should have IEnumerable<MovigngAverage>  to hold the reference to that object. Try like following :

 IEnumerable<MovingAverage> SMA = SimpleMovingAverage(stocks, period);

and if you are returning a single object, then you need to change the return type of the method :

private static MovingAverage SimpleMovingAverage(
        IEnumerable<IexTradingStock> queue, int period)
{
   // code here

   return movignAeverage;
}

and now you should be able to do :

MovingAverage = SimpleMovingAverage(stocks, period);

Hope it helps!


这篇关于分配函数的返回IEnumerable&lt; MovingAverage&gt;价值到另一个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆