C# passing values from one method to another

后端 未结 3 1833
北荒
北荒 2021-01-17 01:38

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. Bu

3条回答
  •  有刺的猬
    2021-01-17 02:27

    You have some options:

    1. have SingleColumn return results and add that as a parameter to SMA
    2. make results a field of the class so it is shared.

    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 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.

提交回复
热议问题