-2

I have a formula which calculates a number, then I need it to take multiples of each of these and store them to an ordered list, as many numbers as it takes to get to 300. I'm confident a for loop is not the best way to do this, but here is what I got.

public List<double> axialLengthFt(double length)
    {
       fundamental = (1130 / 2) / length;

       for (int i = 1; i < 15; i++)
       {    
           double d = fundamental * i;
           if (d <= 300)
              modes.Add(d); //NullReferenceException here??
           else
               break;              
       }
        return modes;
    }

I don't know why I am getting the NullReferenceException, please help!

2
  • 1
    Where do you declare modes? List<double> modes = new List<double>(); should solve the problem.
    – jAC
    Jan 23, 2013 at 20:32
  • As a field above, I forgot new List<double>(). Thanks!
    – Agentgreen
    Jan 25, 2013 at 0:49

1 Answer 1

5

You are never declaring the variable modes.

List<double> modes = new List<double>();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.