我得到的结果错误代码。下面的代码。我基本上想从 SingleColumn 方法的数据集,并在 SMA 方法使用它。但我在目前的情况下不存在得到结果DEOS。
的静态公共无效SMA() {双击[] = closePrice results.ToArray();
下面你可以看到 SingleColumn 和零件的 SMA 代码。
#地区的单立柱 //静态公共双重效果; 静态公共无效SingleColumn(IEnumerable的<串>可疑交易报告,INT highNum) {#地区泻数据列 Console.WriteLine(单列查询:); VAR columnQuery =从可疑交易报告线让元素= line.Split('')选择Convert.ToDouble(元素[highNum]); 变种结果= columnQuery.ToList(); 双[] = closePrice results.ToArray(); #endregion #地区的最大值,最小值,平均值双平均= results.Average(); 双最大值= results.Max(); 双分钟= results.Min(); Console.WriteLine(高:{0}:低:{1}:平均:{2:0.00},最大值,最小值,平均值); #endregion } #地区的战略码SMA 静态公共无效SMA() {双[] = closePrice结果。 ToArray的(); INT TOTAL_PERIODS = closePrice.Length; 双[] =输出新的双[TOTAL_PERIODS] INT开始; INT长度; 的for(int i = 0; I< closePrice.Length-TOTAL_PERIODS;我++)//不得不从-1改为-TOTAL_PERIODS { closePrice [I] =(双)我; } TicTacTec.TA.Library.Core.RetCode RETCODE = Core.Sma(0,closePrice.Length-1,closePrice,PERIODS_AVERAGE,开始出来,出来的长度,输出);解决方案
您有一些选择:
选项1是更清洁,因为它迫使主叫方呼叫 SingleColumn 第一(或拿出自己的列表)
静态公网双[] SingleColumn (IEnumerable的<串GT;可疑交易报告,INT highNum) {:返回closePrice; } #地区的战略码SMA 静态公共无效SMA(双[] closePrice) { INT TOTAL_PERIODS = closePrice.Length; 双[] =输出新的双[TOTAL_PERIODS] :}请注意,我是从改变了你的输出/输入结果到 closePrice ,因为它只是将其转换为一个List和背部。这只是清洁离开它作为一个双[] 。您也可以只使用清理代码位的的ToArray 而不是使用了ToList 和然后 的ToArray 。
I am getting an error code in the result. code below. I am basically trying to get a data set from SingleColumn method and use it in SMA method. But I am getting results deos not exist in current context.
static public void SMA() { double[] closePrice = results.ToArray();Below you can see the SingleColumn and part of SMA code.
#region Single Column //static public double results; static public void SingleColumn(IEnumerable<string> strs, int highNum) { #region spilt data to columns Console.WriteLine("Single Column Query:"); var columnQuery = from line in strs let elements = line.Split(',') select Convert.ToDouble(elements[highNum]); var results = columnQuery.ToList(); double[] closePrice = results.ToArray(); #endregion #region max, min, avg double average = results.Average(); double max = results.Max(); double min = results.Min(); Console.WriteLine("High: {0}: Low: {1}: Average: {2:0.00}", max, min, average); #endregion } #region Strategy Code SMA static public void SMA() { double[] closePrice = results.ToArray(); int TOTAL_PERIODS = closePrice.Length; double[] output = new double[TOTAL_PERIODS]; int begin; int length; for (int i = 0; i < closePrice.Length-TOTAL_PERIODS; i++) //had to change from -1 to -TOTAL_PERIODS { closePrice[i] = (double)i; } TicTacTec.TA.Library.Core.RetCode retCode = Core.Sma(0, closePrice.Length-1, closePrice, PERIODS_AVERAGE, out begin, out length, output);解决方案
You have some options:
Option 1. is cleaner since it forces callers to call SingleColumn first (or come up with a list on their own)
static public double[] SingleColumn(IEnumerable<string> strs, int highNum) { ... return closePrice; } #region Strategy Code SMA static public void SMA(double[] closePrice) { int TOTAL_PERIODS = closePrice.Length; double[] output = new double[TOTAL_PERIODS]; ... }Note that I changed your output/input from result to closePrice since it was just converting it to a List and back. It's cleaner just to leave it as a double[]. You can also clean up the code a bit by just using ToArray instead of using ToList and then ToArray.
更多推荐
C#传递值从一个方法到另一个
发布评论