I created an array of objects like this. But in order to assign a value to an object, do I need to instantiate each object at each position of the array? Why do I need it?
This is my method
StageObject[] StageSplitDate = new StageObject[Stages.Rows.Count]; for (int i = 0; i < Stages.Rows.Count; i++) { StageSplitDate[i] = new StageObject(); StageSplitDate[i].StageId = "String Value"; StageSplitDate[i].FromTime = StartTime; StartTime =StartTime.AddMinutes(Convert.ToDouble(10)); StageSplitDate[i].ToTime = StartTime; } return StageSplitDate;
And the class of the object
public class StageObject { public string StageId { get; set; } public DateTime FromTime { get; set; } public DateTime ToTime { get; set; } }
source share