I have a class which allows me to store a time as follows.
class LockTime
{
public int Start { get; set; }
public int End {get; set; }
public LockTime (int start, int end)
{
Start = start;
End = end;
}
}
In another class I declare a list of this object.
private List<LockTime> listOfTimes;
I have a method in this 2nd class to then add to this list.
LockTime theTime = new LockTime((pickerTimeStart.Value.Hour + pickerTimeStart.Value.Minute), (pickerTimeEnd.Value.Hour + pickerTimeEnd.Value.Minute));
listOfTimes.Add(theTime);
When it trys to add to the list it throws the NullPointerException. In the debugger it shows 2 values in theTime variable. I don't quite understand why it's saying NullPointer.
Also at the start where I've declared listOfTimes it is underlined blue saying that the field is never assigned to anything and will always have a null value.
This small little issue is driving me nuts, am I just completely missing something. Please help!
listOfItems?listOfTimes = new List<LockTime>();?