Possible Duplicate:
What is a NullReferenceException in .NET?
I have a Model (ASP.NET MVC 4, C#) Called HoursOfOperation:
public class HoursOfOperation
{
public List<DayTimes> Monday { get; set; }
public List<DayTimes> Tuesday { get; set; }
public List<DayTimes> Wednesday { get; set; }
public List<DayTimes> Thursday { get; set; }
public List<DayTimes> Friday { get; set; }
public List<DayTimes> Saturday { get; set; }
public List<DayTimes> Sunday { get; set; }
}
and a DayTimes
public class DayTimes
{
public int Status { get; set; }
public string From { get; set; }
public string To { get; set; }
}
now I'm trying to add a new set to the Monday entity like below:
var _vm = new HoursOfOperation();
_vm.Monday.Add(new DayTimes{
From = day.From.ToString(),
To = day.To.ToString(),
Status = (int)day.Status
});
as soon as the above statement is excecuted I'm getting a "Object reference not set to an instance of an object."
Exception
Now I have checked and day.From.ToString()
has a "08:00:00"
, day.To.ToString() has "09:30:00"
and day.Status has a 1
at the time at which this statement throws the exception.
Any Ideas?