Im populating a List with my object (Event).
The object has a field called DocumentDate that is what I wish to update in each item.
But after the loop, all items in the list are the same! I want to know why:
The code:
private List<Events> CreateEventsBetween(string start, string end, string repeatState, Event defaultEvent)
{
var states = Resources.GetStringArray(Resource.Array.repeat_states);
DateTime.TryParse(start, out DateTime dtStart);
DateTime.TryParse(end, out DateTime dtEnd);
List<Event> events = new List<Event>();
if (repeatState == states[0])
while(dtStart<= dtEnd)
{
var e = defaultEvent;
e.DocumentDate = dtStart;
events.Add(e);
dtStart= dtStart.AddDays(i);
}
...
...
...
return events;
}
Here every item in the list of events have the same DocumentDate's, when they should have different ones