I have a simple Class that I thought I could make more useful if I added a list property to store some values ( i dont want an array bc I dont know how long it will be)
public class MyClass
{
public double myProperty1;
public double myProperty2;
//etc
public List<double> myList {get; set;}
}
but when I try to access this property, for example by
if x >y
newObject.myList.Add(x);
I get an error. Object reference not set to an instance of an object.
Any ideas what I am doing wrong here.
Your class instances need an actual
List<>instance. The right place to create it is in a constructor. The private setter is usually a good idea but not essential.