-2

How may I call a method in another class from another class in a separate file. The files are in the same directory. I tried calling this SMAMethod method

namespace myBackEnd
{
    public class SMA
    {
        public static Models.DateClose SMAMethod (Queue<Models.DateClose> 
        queue, int period)
        {
            decimal average, sum=0;
            Models.DateClose dateClose = null;
            for (int i = 0; i < period; i++)
            {
                dateClose = queue.Dequeue();
                if (dateClose != null)
                    sum += dateClose.Close;
            }
            average = sum/period;
            dateClose.Close = average;

            return dateClose;

        }
    }
}

When I call the SMAMethod in I get the red squiggly line with the hover over text " SMAMethod does not exists in the current context"

SMAMethod(movingAverageQueue, 10);
Jam66125
  • 163
  • 2
  • 8

1 Answers1

2

You need to specify the class that it's in. Try this:

myBackEnd.SMA.SMAMethod(movingAverageQueue, 10);

myBackEnd is the namespace, it will be unnecessary if your other class is in the same namespace.

SMA is the class that your method exists in. This is required.

MikeH
  • 4,242
  • 1
  • 17
  • 32