我已经创建了一个像这样的对象数组。但是要为对象赋值,我必须在数组的每个位置实例化每个对象吗?为什么我需要这个?
这是我的方法
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;
和对象等级
public class StageObject
{
public string StageId { get; set; }
public DateTime FromTime { get; set; }
public DateTime ToTime { get; set; }
}